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