You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.9 KiB

  1. From 351ee477f713730d1c53cf26b6fb87706d268a5f Mon Sep 17 00:00:00 2001
  2. From: Chris Leech <cleech@redhat.com>
  3. Date: Tue, 13 Aug 2013 12:39:07 -0700
  4. Subject: [PATCH 1/1] idbw_rec_write, pick tpgt from existing record
  5. On a static add (-m node -o new) without a user specified tpgt, looks
  6. for existing new style records with tpgt before creating an old style
  7. record without. If one exists, take the tpgt from it an write an
  8. updated new style record instead.
  9. ---
  10. usr/idbm.c | 40 ++++++++++++++++++++++++++++++++++++++++
  11. 1 file changed, 40 insertions(+)
  12. --- a/usr/idbm.c
  13. +++ b/usr/idbm.c
  14. @@ -28,6 +28,7 @@
  15. #include <dirent.h>
  16. #include <limits.h>
  17. #include <fcntl.h>
  18. +#include <glob.h>
  19. #include <sys/stat.h>
  20. #include <sys/file.h>
  21. #include <inttypes.h>
  22. @@ -44,6 +45,10 @@
  23. #include "fw_context.h"
  24. #include "iscsi_err.h"
  25. +#ifndef GLOB_ONLYDIR
  26. +#define GLOB_ONLYDIR 0x100
  27. +#endif
  28. +
  29. #define IDBM_HIDE 0 /* Hide parameter when print. */
  30. #define IDBM_SHOW 1 /* Show parameter when print. */
  31. #define IDBM_MASKED 2 /* Show "stars" instead of real value when print */
  32. @@ -203,6 +208,8 @@ static struct int_list_tbl {
  33. { "SHA3-256", AUTH_CHAP_ALG_SHA3_256 },
  34. };
  35. +static int idbm_remove_disc_to_node_link(node_rec_t *rec, char *portal);
  36. +
  37. static void
  38. idbm_recinfo_discovery(discovery_rec_t *r, recinfo_t *ri)
  39. {
  40. @@ -2207,12 +2214,49 @@ static int idbm_rec_write_old(node_rec_t
  41. FILE *f;
  42. char *portal;
  43. int rc = 0;
  44. + glob_t globbuf;
  45. + size_t i;
  46. + int tpgt = PORTAL_GROUP_TAG_UNKNOWN;
  47. portal = malloc(PATH_MAX);
  48. if (!portal) {
  49. log_error("Could not alloc portal");
  50. return ISCSI_ERR_NOMEM;
  51. }
  52. +
  53. + /* check for newer portal dir with tpgt */
  54. + snprintf(portal, PATH_MAX, "%s/%s/%s,%d,*", NODE_CONFIG_DIR,
  55. + rec->name, rec->conn[0].address, rec->conn[0].port);
  56. + rc = glob(portal, GLOB_ONLYDIR, NULL, &globbuf);
  57. + if (!rc) {
  58. + if (globbuf.gl_pathc > 1)
  59. + log_warning("multiple tpg records for portal "
  60. + "%s/%s:%d found", rec->name,
  61. + rec->conn[0].address, rec->conn[0].port);
  62. + /* set pattern for sscanf matching of tpgt */
  63. + snprintf(portal, PATH_MAX, "%s/%s/%s,%d,%%u", NODE_CONFIG_DIR,
  64. + rec->name, rec->conn[0].address, rec->conn[0].port);
  65. + for (i = 0; i < globbuf.gl_pathc; i++) {
  66. + rc = sscanf(globbuf.gl_pathv[i], portal, &tpgt);
  67. + if (rc == 1)
  68. + break;
  69. + }
  70. + if (tpgt == PORTAL_GROUP_TAG_UNKNOWN)
  71. + log_warning("glob match on existing records, "
  72. + "but no valid tpgt found");
  73. + }
  74. + globfree(&globbuf);
  75. + rc = 0;
  76. +
  77. + /* if a tpgt was selected from an old record, write entry in new format */
  78. + if (tpgt != PORTAL_GROUP_TAG_UNKNOWN) {
  79. + log_warning("using tpgt %u from existing record", tpgt);
  80. + rec->tpgt = tpgt;
  81. + rc = idbm_remove_disc_to_node_link(rec, portal);
  82. + free(portal);
  83. + return idbm_rec_write_new(rec);
  84. + }
  85. +
  86. snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
  87. rec->name, rec->conn[0].address, rec->conn[0].port);