Hello,

We had a use case, where we had to log into multiple iSCSI targets in 
parallel. And it was important for these operations to complete in a timely 
manner.
We found 2 major codes that caused large delays in the login command:
1. idbm_lock() and idbm_unlock() APIs
2. session_is_running() duplicate session checking code. This performs the 
entire sysfs scan for each logged in target and results in O(n^2) sysfs 
lookups, causing huge delays, when there are multiple iSCSI targets logged 
into.

We have a patch for issue #1 above and have attached it.
This definitely optimized the login times, as the code now does not perform 
redundant sleeps.
Would be great if someone could review this patch, and see if this could be 
generally useful to optimize the login times.

Thanks,
Satyajit

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/open-iscsi.
For more options, visit https://groups.google.com/d/optout.
diff -uNr open-iscsi-2.0.874/usr/idbm.c open-iscsi-2.0.874_2/usr/idbm.c
--- open-iscsi-2.0.874/usr/idbm.c	2018-11-01 20:35:07.416696650 +0000
+++ open-iscsi-2.0.874_2/usr/idbm.c	2018-11-01 20:55:45.978146609 +0000
@@ -1330,7 +1330,7 @@
  return 0;
 }

-int idbm_lock(void)
+int idbm_lock_old(void)
  {
  int fd, i, ret;

@@ -1371,7 +1371,7 @@
  return 0;
  }

-void idbm_unlock(void)
+void idbm_unlock_old(void)
  {
  if (db->refs > 1) {
    db->refs--;
@@ -1382,6 +1382,41 @@
  unlink(LOCK_WRITE_FILE);
  }

+int idbm_lock(void)
+{
+	int fd, i, ret;
+	struct flock f;
+	memset(&f, 0, sizeof(f));
+	f.l_type = F_WRLCK;
+
+	fd = open(LOCK_FILE, O_RDWR | O_CREAT, 0666);
+	if (fd < 0) {
+		log_error("Failed to open idbm lock file %s", LOCK_FILE);
+		return -1;
+	}
+	ret = fcntl(fd, F_SETLKW, &f);
+	return ret;
+}
+
+void idbm_unlock(void)
+{
+	int fd, i, ret;
+	struct flock f;
+	memset(&f, 0, sizeof(f));
+	f.l_type = F_UNLCK;
+
+	fd = open(LOCK_FILE, O_RDWR, 0666);
+	if (fd < 0) {
+		log_warning("Failed to open idbm lock file %s", LOCK_FILE);
+		return;
+	}
+	ret = fcntl(fd, F_SETLKW, &f);
+	if (ret != 0) {
+		log_warning("Failed to unlock idbm lock file %s", LOCK_FILE);
+	}
+	return;
+}
+
 /*
  * Backwards Compat:
  * If the portal is a file then we are doing the old style default
diff -uNr open-iscsi-2.0.874/usr/idbm.h open-iscsi-2.0.874_2/usr/idbm.h
--- open-iscsi-2.0.874/usr/idbm.h	2018-11-01 20:35:07.416696650 +0000
+++ open-iscsi-2.0.874_2/usr/idbm.h	2018-11-01 20:56:11.678410471 +0000
@@ -163,6 +163,8 @@
 /* lower level idbm functions for use by iface.c */
 extern void idbm_recinfo_config(recinfo_t *info, FILE *f);
 extern void idbm_recinfo_iface(struct iface_rec *r, recinfo_t *ri);
+extern int idbm_lock_old(void);
+extern void idbm_unlock_old(void);
 extern int idbm_lock(void);
 extern void idbm_unlock(void);
 extern recinfo_t *idbm_recinfo_alloc(int max_keys);

Reply via email to