[stgt] Online resizing of LUN's

RedShift redshift at pandora.be
Fri Jun 22 08:32:16 CEST 2012


On 06/18/2012 03:21 PM, FUJITA Tomonori wrote:
> On Mon, 18 Jun 2012 15:12:37 +0200 (CEST)
> RedShift<redshift at telenet.be>  wrote:
>
>> So the patch in the email posted above should work? Will try that ASAP.
>
> Not sure. Too many changes since then. The following patch can be
> applied to the current git head. But not sure if it works.
> *snip*


It doesn't work.

I use an LVM logical volume as backing-store to my iSCSI target. I started tgtd, connected my initiator and then proceeded with resizing my logical volume by adding 5 GB. Next, I rescanned the disks from disk management (I'm using Windows as initiator), however, no size changed occured nor does tgtd say so.

I ran tgtd -f -d 1, and it says

# tgtd -d 1 -f
tgtd: setup_inotify(320) inotify ready, 0


But it never mentions "%s changed"


I modified the patch so it would apply cleanly to 1.0.28, below


Thanks,


Only in fujita-tgt-5e053ca-with-resize/doc: htmlpages
Only in fujita-tgt-5e053ca-with-resize/doc: manpages
diff -r -u fujita-tgt-5e053ca/usr/bs.c fujita-tgt-5e053ca-with-resize/usr/bs.c
--- fujita-tgt-5e053ca/usr/bs.c	2012-06-02 16:04:54.000000000 +0200
+++ fujita-tgt-5e053ca-with-resize/usr/bs.c	2012-06-21 20:03:19.059142000 +0200
@@ -32,6 +32,7 @@
  #include <sys/types.h>
  #include <sys/epoll.h>
  #include <linux/types.h>
+#include <sys/inotify.h>

  #include "list.h"
  #include "tgtd.h"
@@ -304,6 +305,22 @@
  	return 1;
  }

+extern void resize_detect(int fd, int events, void *data);
+
+void setup_inotify(void)
+{
+    int ret;
+
+    inotify_fd = inotify_init1(IN_NONBLOCK);
+    if (inotify_fd < 0)
+        eprintf("lun size change detection is disabled\n");
+    else {
+        ret = tgt_event_add(inotify_fd, EPOLLIN,
+            resize_detect, NULL);
+        eprintf("inotify ready, %d\n", ret);
+    }
+}
+
  int bs_init(void)
  {
  	int ret;
@@ -311,12 +328,14 @@
  	ret = bs_init_signalfd();
  	if (!ret) {
  		eprintf("use signalfd notification\n");
+        setup_inotify();
  		return 0;
  	}

  	ret = bs_init_notify_thread();
  	if (!ret) {
  		eprintf("use pthread notification\n");
+        setup_inotify();
  		return 0;
  	}

diff -r -u fujita-tgt-5e053ca/usr/bs_rdwr.c fujita-tgt-5e053ca-with-resize/usr/bs_rdwr.c
--- fujita-tgt-5e053ca/usr/bs_rdwr.c	2012-06-02 16:04:54.000000000 +0200
+++ fujita-tgt-5e053ca-with-resize/usr/bs_rdwr.c	2012-06-21 20:04:42.105141000 +0200
@@ -33,6 +33,7 @@

  #include <linux/fs.h>
  #include <sys/epoll.h>
+#include <sys/inotify.h>

  #include "list.h"
  #include "util.h"
@@ -269,6 +270,7 @@
  static int bs_rdwr_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)
  {
  	uint32_t blksize = 0;
+    int ret;

  	*fd = backed_file_open(path, O_RDWR|O_LARGEFILE|lu->bsoflags, size,
  				&blksize);
@@ -284,6 +286,17 @@
  	if (!lu->attrs.no_auto_lbppbe)
  		update_lbppbe(lu, blksize);

+    if (inotify_fd > 0) {
+        ret = inotify_add_watch(inotify_fd, path, IN_CLOSE_WRITE);
+        if (ret < 0)
+            eprintf("can't check %s\n", path);
+        else {
+            eprintf("checking %s\n", path);
+            lu->notify_fd = ret;
+        }
+    }
+
+
  	return 0;
  }

diff -r -u fujita-tgt-5e053ca/usr/target.c fujita-tgt-5e053ca-with-resize/usr/target.c
--- fujita-tgt-5e053ca/usr/target.c	2012-06-02 16:04:54.000000000 +0200
+++ fujita-tgt-5e053ca-with-resize/usr/target.c	2012-06-21 20:14:00.275112000 +0200
@@ -29,6 +29,7 @@
  #include <unistd.h>
  #include <sys/socket.h>
  #include <sys/time.h>
+#include <sys/inotify.h>

  #include "list.h"
  #include "util.h"
@@ -41,6 +42,39 @@
  #include "spc.h"

  static LIST_HEAD(device_type_list);
+static LIST_HEAD(target_list);
+
+void resize_detect(int fd, int events, void *data)
+{
+    struct target *target;
+    struct scsi_lu *lu;
+    struct inotify_event e;
+    int ret;
+
+    ret = read(fd, (char *)&e, sizeof(e));
+
+    eprintf("resize, %d\n", ret);
+    if (ret < 0)
+        return;
+
+    list_for_each_entry(target, &target_list, target_siblings) {
+        list_for_each_entry(lu, &target->device_list, device_siblings) {
+            if (lu->notify_fd == e.wd) {
+                uint64_t size;
+                uint32_t blksize = 0;
+                int fd;
+                eprintf("%s changed\n", lu->path);
+                fd = backed_file_open(lu->path, O_RDONLY, &size, &blksize);
+                if (fd > 0) {
+                    eprintf("new size %lld\n", (long long)size);
+                    close(fd);
+                    lu->size = size;
+                } else
+                    eprintf("failed to open\n");
+                }
+        }
+    }
+}

  static struct target global_target;

@@ -61,7 +95,7 @@
  	return NULL;
  }

-static LIST_HEAD(target_list);
+

  static struct target *target_lookup(int tid)
  {
diff -r -u fujita-tgt-5e053ca/usr/tgtd.c fujita-tgt-5e053ca-with-resize/usr/tgtd.c
--- fujita-tgt-5e053ca/usr/tgtd.c	2012-06-02 16:04:54.000000000 +0200
+++ fujita-tgt-5e053ca-with-resize/usr/tgtd.c	2012-06-21 20:08:03.391241000 +0200
@@ -45,6 +45,7 @@
  unsigned long pagesize, pageshift;

  int system_active = 1;
+int inotify_fd = -1;
  static int ep_fd;
  static char program_name[] = "tgtd";
  static LIST_HEAD(tgt_events_list);
diff -r -u fujita-tgt-5e053ca/usr/tgtd.h fujita-tgt-5e053ca-with-resize/usr/tgtd.h
--- fujita-tgt-5e053ca/usr/tgtd.h	2012-06-02 16:04:54.000000000 +0200
+++ fujita-tgt-5e053ca-with-resize/usr/tgtd.h	2012-06-21 20:09:59.438105000 +0200
@@ -168,6 +168,7 @@
  	uint64_t size;
  	uint64_t lun;
  	char *path;
+    int notify_fd;
  	int bsoflags;
  	unsigned int blk_shift;

@@ -226,6 +227,7 @@

  extern int system_active;
  extern int is_debug;
+extern int inotify_fd;
  extern int nr_iothreads;
  extern struct list_head bst_list;

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list