[Stgt-devel] [PATCH] add stgt_device_template example

FUJITA Tomonori tomof at acm.org
Tue Aug 23 17:05:03 CEST 2005


From: Mike Christie <michaelc at cs.wisc.edu>
Subject: [Stgt-devel] [PATCH] add stgt_device_template example
Date: Tue, 23 Aug 2005 00:59:16 -0500

> This adds the beginings of a stgt_device_template for
> passthrough commands. It will end up using the block
> layer BLOCK_PC facility to pass the command to the
> underlying device similar to how we do it for SG_IO
> and dm-multipath hw_handlers like dm-emc.c.
> 
> It is not completely hooked in yet. The command
> handling needs to be done and so does the actual
> device creation.
> 
> This was built over my last patch.

I've attached the patch to enable IET to use your new features. Now we
can use 'Lun' in the IET configure file (/etc/ietd.conf) again.

For example, I put 'Lun 0 Path=/dev/hdb' line in my configuration
file.

fujita at lily:/sys/class$ find stgt_*
stgt_device
stgt_device/device0
stgt_device/device0/path
stgt_target
stgt_target/target0
stgt_target/target0/queued_cmnds

fujita at lily:/sys/class$ cat stgt_device/device0/path
/dev/hdb


diff -x CVS -x .svn -x GPATH -x GRTAGS -x GSYMS -x GTAGS -x .config -u --new-file --recursive stgt.new/iscsi/kernel/config.c stgt.work/iscsi/kernel/config.c
--- stgt.new/iscsi/kernel/config.c	2005-08-19 00:42:26.000000000 +0900
+++ stgt.work/iscsi/kernel/config.c	2005-08-23 22:29:50.000000000 +0900
@@ -170,8 +170,7 @@
 	if ((err = copy_from_user(&info, (void *) ptr, sizeof(info))) < 0)
 		return err;
 
-	return 0;
-/* 	return volume_add(target, &info); */
+	return volume_add(target, &info);
 }
 
 static int del_volume(struct iscsi_target *target, unsigned long ptr)
@@ -182,8 +181,7 @@
 	if ((err = copy_from_user(&info, (void *) ptr, sizeof(info))) < 0)
 		return err;
 
-	return 0;
-/* 	return iscsi_volume_del(target, &info); */
+	return volume_del(target, &info);
 }
 
 static int iscsi_param_config(struct iscsi_target *target, unsigned long ptr, int set)
diff -x CVS -x .svn -x GPATH -x GRTAGS -x GSYMS -x GTAGS -x .config -u --new-file --recursive stgt.new/iscsi/kernel/iscsi.h stgt.work/iscsi/kernel/iscsi.h
--- stgt.new/iscsi/kernel/iscsi.h	2005-08-23 18:56:10.000000000 +0900
+++ stgt.work/iscsi/kernel/iscsi.h	2005-08-23 22:48:38.000000000 +0900
@@ -73,6 +73,7 @@
 	struct iscsi_trgt_param trgt_param;
 
 	struct list_head session_list;
+	struct list_head device_list;
 
 	struct network_thread_info nthread_info;
 
@@ -231,6 +232,8 @@
 struct iscsi_target *target_lookup_by_id(u32);
 extern int target_add(struct target_info *);
 extern int target_del(u32 id);
+extern int volume_del(struct iscsi_target *target, struct volume_info *info);
+extern int volume_add(struct iscsi_target *target, struct volume_info *info);
 
 /* config.c */
 extern int iet_procfs_init(void);
diff -x CVS -x .svn -x GPATH -x GRTAGS -x GSYMS -x GTAGS -x .config -u --new-file --recursive stgt.new/iscsi/kernel/target.c stgt.work/iscsi/kernel/target.c
--- stgt.new/iscsi/kernel/target.c	2005-08-23 18:56:10.000000000 +0900
+++ stgt.work/iscsi/kernel/target.c	2005-08-23 23:25:50.000000000 +0900
@@ -11,6 +11,7 @@
 #include <iscsi_dbg.h>
 #include <stgt.h>
 #include <stgt_target.h>
+#include <stgt_device.h>
 
 #define	MAX_NR_TARGETS	(1UL << 30)
 
@@ -151,6 +152,7 @@
 	init_MUTEX(&target->target_sem);
 
 	INIT_LIST_HEAD(&target->session_list);
+	INIT_LIST_HEAD(&target->device_list);
 	list_add(&target->t_list, &target_list);
 
 	nthread_init(target);
@@ -277,3 +279,79 @@
 
 	return 0;
 }
+
+/*
+ * Temporary device code
+ */
+
+struct iscsi_device {
+	uint64_t lun;
+	struct list_head list;
+	struct stgt_device *sd;
+};
+
+struct iscsi_device *volume_lookup(struct iscsi_target *target, u32 lun)
+{
+	struct iscsi_device *device;
+	list_for_each_entry(device, &target->device_list, list) {
+		if (device->lun == lun)
+			return device;
+	}
+	return NULL;
+}
+
+int volume_add(struct iscsi_target *target, struct volume_info *info)
+{
+	char *path, *type, dtype[] = "stgt_sd";
+	struct iscsi_device *device;
+	struct stgt_device *sd;
+
+	eprintk("%u %s\n", info->lun, info->args);
+
+	if (volume_lookup(target, info->lun)) {
+		eprintk("%u\n", info->lun);
+		return -EEXIST;
+	}
+
+	path = strstr(info->args, "Path=");
+	if (!path)
+		return -EINVAL;
+	path += strlen("Path=");
+
+	device = kmalloc(sizeof(*device), GFP_KERNEL);
+	if (!device)
+		return -ENOMEM;
+
+	type = strstr(info->args, "Type=");
+	if (type)
+		type += strlen("Type=");
+	else
+		type = dtype;
+
+	eprintk("%u %s %s\n", info->lun, path, type);
+	sd = stgt_device_create(target->stt, type, path, info->lun, 0);
+	if (!sd)
+		goto out;
+
+	device->sd = sd;
+	device->lun = info->lun;
+	list_add(&device->list, &target->device_list);
+	return 0;
+out:
+	kfree(device);
+	return -EINVAL;
+}
+
+int volume_del(struct iscsi_target *target, struct volume_info *info)
+{
+	struct iscsi_device *device;
+
+	device = volume_lookup(target, info->lun);
+	if (!device)
+		return -ENOENT;
+
+	stgt_device_destroy(device->sd);
+	list_del(&device->list);
+	kfree(device);
+	return 0;
+}



More information about the stgt mailing list