|
|
5f4533 |
From bf6a05987a418e4d7eeb3a24f0912c5cfc9e533d Mon Sep 17 00:00:00 2001
|
|
|
62f653 |
From: Chris Leech <cleech@redhat.com>
|
|
|
62f653 |
Date: Tue, 13 Aug 2013 12:39:07 -0700
|
|
|
5f4533 |
Subject: [PATCH] idbw_rec_write, pick tpgt from existing record
|
|
|
62f653 |
|
|
|
62f653 |
On a static add (-m node -o new) without a user specified tpgt, looks
|
|
|
62f653 |
for existing new style records with tpgt before creating an old style
|
|
|
62f653 |
record without. If one exists, take the tpgt from it an write an
|
|
|
62f653 |
updated new style record instead.
|
|
|
62f653 |
---
|
|
|
62f653 |
usr/idbm.c | 40 ++++++++++++++++++++++++++++++++++++++++
|
|
|
62f653 |
1 file changed, 40 insertions(+)
|
|
|
62f653 |
|
|
|
62f653 |
diff --git a/usr/idbm.c b/usr/idbm.c
|
|
|
5f4533 |
index c29cbed..00955e4 100644
|
|
|
62f653 |
--- a/usr/idbm.c
|
|
|
62f653 |
+++ b/usr/idbm.c
|
|
|
62f653 |
@@ -28,6 +28,7 @@
|
|
|
62f653 |
#include <dirent.h>
|
|
|
62f653 |
#include <limits.h>
|
|
|
62f653 |
#include <fcntl.h>
|
|
|
62f653 |
+#include <glob.h>
|
|
|
62f653 |
#include <sys/stat.h>
|
|
|
62f653 |
#include <sys/file.h>
|
|
|
5f4533 |
#include <inttypes.h>
|
|
|
5f4533 |
@@ -164,6 +165,8 @@ static struct idbm *db;
|
|
|
62f653 |
_n++; \
|
|
|
62f653 |
} while(0)
|
|
|
62f653 |
|
|
|
62f653 |
+static int idbm_remove_disc_to_node_link(node_rec_t *rec, char *portal);
|
|
|
62f653 |
+
|
|
|
62f653 |
static void
|
|
|
62f653 |
idbm_recinfo_discovery(discovery_rec_t *r, recinfo_t *ri)
|
|
|
62f653 |
{
|
|
|
5f4533 |
@@ -2080,12 +2083,49 @@ static int idbm_rec_write_old(node_rec_t *rec)
|
|
|
62f653 |
FILE *f;
|
|
|
62f653 |
char *portal;
|
|
|
62f653 |
int rc = 0;
|
|
|
62f653 |
+ glob_t globbuf;
|
|
|
62f653 |
+ int i;
|
|
|
62f653 |
+ int tpgt = PORTAL_GROUP_TAG_UNKNOWN;
|
|
|
62f653 |
|
|
|
62f653 |
portal = malloc(PATH_MAX);
|
|
|
62f653 |
if (!portal) {
|
|
|
62f653 |
log_error("Could not alloc portal");
|
|
|
62f653 |
return ISCSI_ERR_NOMEM;
|
|
|
62f653 |
}
|
|
|
62f653 |
+
|
|
|
62f653 |
+ /* check for newer portal dir with tpgt */
|
|
|
62f653 |
+ snprintf(portal, PATH_MAX, "%s/%s/%s,%d,*", NODE_CONFIG_DIR,
|
|
|
62f653 |
+ rec->name, rec->conn[0].address, rec->conn[0].port);
|
|
|
62f653 |
+ rc = glob(portal, GLOB_ONLYDIR, NULL, &globbuf);
|
|
|
62f653 |
+ if (!rc) {
|
|
|
62f653 |
+ if (globbuf.gl_pathc > 1)
|
|
|
62f653 |
+ log_warning("multiple tpg records for portal "
|
|
|
62f653 |
+ "%s/%s:%d found", rec->name,
|
|
|
62f653 |
+ rec->conn[0].address, rec->conn[0].port);
|
|
|
62f653 |
+ /* set pattern for sscanf matching of tpgt */
|
|
|
62f653 |
+ snprintf(portal, PATH_MAX, "%s/%s/%s,%d,%%u", NODE_CONFIG_DIR,
|
|
|
62f653 |
+ rec->name, rec->conn[0].address, rec->conn[0].port);
|
|
|
62f653 |
+ for (i = 0; i < globbuf.gl_pathc; i++) {
|
|
|
62f653 |
+ rc = sscanf(globbuf.gl_pathv[i], portal, &tpgt);
|
|
|
62f653 |
+ if (rc == 1)
|
|
|
62f653 |
+ break;
|
|
|
62f653 |
+ }
|
|
|
62f653 |
+ if (tpgt == PORTAL_GROUP_TAG_UNKNOWN)
|
|
|
62f653 |
+ log_warning("glob match on existing records, "
|
|
|
62f653 |
+ "but no valid tpgt found");
|
|
|
62f653 |
+ }
|
|
|
62f653 |
+ globfree(&globbuf);
|
|
|
62f653 |
+ rc = 0;
|
|
|
62f653 |
+
|
|
|
62f653 |
+ /* if a tpgt was selected from an old record, write entry in new format */
|
|
|
62f653 |
+ if (tpgt != PORTAL_GROUP_TAG_UNKNOWN) {
|
|
|
62f653 |
+ log_warning("using tpgt %u from existing record", tpgt);
|
|
|
62f653 |
+ rec->tpgt = tpgt;
|
|
|
62f653 |
+ rc = idbm_remove_disc_to_node_link(rec, portal);
|
|
|
62f653 |
+ free(portal);
|
|
|
62f653 |
+ return idbm_rec_write_new(rec);
|
|
|
62f653 |
+ }
|
|
|
62f653 |
+
|
|
|
62f653 |
snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
|
|
|
62f653 |
rec->name, rec->conn[0].address, rec->conn[0].port);
|
|
|
62f653 |
|
|
|
62f653 |
--
|
|
|
5f4533 |
2.21.0
|
|
|
62f653 |
|