All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHSET 0/4] Auto-login support for the pnfs-objects protocol
@ 2012-03-16  6:17 Boaz Harrosh
  2012-03-16  6:19 ` [PATCH 1/4] pnfsd-exofs: Add autologin support to exofs Boaz Harrosh
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-16  6:17 UTC (permalink / raw)
  To: Trond Myklebust, Benny Halevy, Steve Dickson, NFS list, open-osd,
	Bhamare, Sachin, Boaz Harrosh
  Cc: Welch, Brent


I'm happy to submit the auto-login support to pnfs-objects protocol.
Please see individual patches for explanations.

It was heavily tested and performs very well.

Submitted, as usual, a patch to pnfsd-exofs that enables this in the pnfs Server
Then follows a modest patch to the pnfs-obj client layout-driver.
And last a patch to the nfs-utils package with a script that executes the
login.

We currently only support the iscsi://ip_addr:ip_port URI protocol.
But other are easy to add by modifying the script, as the Kernel part
is just a transparent pass through between the Server and the osd_login
script.

Benny: As the editor of the STD please review and confirm

List of Patches:
[PATCH 1/4] pnfsd-exofs:  Add autologin support to exofs
	
	This patch is for Benny's pnfsd tree. Thanks

[PATCH 2/4] pnfs-obj: Remove unused variable from objlayout_get_deviceinfo().

	Trond: This is not important just something found when coding.
	
[PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin

	Trond: If at all possible to make the merge window with this one
	It would be great. Thanks.

[PATCH 4/4] osd_login: Add autologin script for objlayoutdriver.

	Steve D: This patch is for you. Thanks a million man, it
	made the complete code Kernel and user-mode 1/7 the size
	Cheers

Thanks
Sachin & Boaz

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/4] pnfsd-exofs:  Add autologin support to exofs
  2012-03-16  6:17 [PATCHSET 0/4] Auto-login support for the pnfs-objects protocol Boaz Harrosh
@ 2012-03-16  6:19 ` Boaz Harrosh
  2012-03-16  6:30   ` Boaz Harrosh
  2012-03-16  6:21 ` [PATCH 2/4] pnfs-obj: Remove unused variable from objlayout_get_deviceinfo() Boaz Harrosh
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-16  6:19 UTC (permalink / raw)
  To: Boaz Harrosh, Trond Myklebust, Benny Halevy, NFS list, open-osd,
	Bhamare, Sachin
  Cc: Steve Dickson, Welch, Brent


Introduce sysfs infrastructure for exofs cluster filesystem.

Each OSD target shows up as below in the sysfs hierarchy:
	/sys/fs/exofs/<osdname>_<partition_id>/devX

where in devX 0 <= X < device_table_size. They are ordered
in device-table order as specified to the mkfs.exofs command

Each OSD device  devX has following attributes :
	osdname - ReadOnly
	systemid - ReadOnly
	uri - Read/Write

It is up to user-mode to update devX/uri for support of
autologin.

Also fixed is the xdr encoding of device_info to support
uri encoding.

Signed-off-by: Sachin Bhamare <sbhamare@panasas.com>
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
 fs/exofs/Kbuild                |    2 +-
 fs/exofs/exofs.h               |    4 +
 fs/exofs/export.c              |    8 ++-
 fs/exofs/super.c               |   14 +++
 fs/exofs/sys.c                 |  202 ++++++++++++++++++++++++++++++++++++++++
 fs/exofs/sys.h                 |   41 ++++++++
 fs/exportfs/pnfs_osd_xdr_srv.c |   45 ++++++++-
 include/linux/pnfs_osd_xdr.h   |    5 +
 8 files changed, 316 insertions(+), 5 deletions(-)
 create mode 100644 fs/exofs/sys.c
 create mode 100644 fs/exofs/sys.h

diff --git a/fs/exofs/Kbuild b/fs/exofs/Kbuild
index 1118068..5f6f1eb 100644
--- a/fs/exofs/Kbuild
+++ b/fs/exofs/Kbuild
@@ -16,6 +16,6 @@
 libore-y := ore.o ore_raid.o
 obj-$(CONFIG_ORE) += libore.o
 
-exofs-y := inode.o file.o symlink.o namei.o dir.o super.o
+exofs-y := inode.o file.o symlink.o namei.o dir.o super.o sys.o
 exofs-$(CONFIG_PNFSD) +=  export.o
 obj-$(CONFIG_EXOFS_FS) += exofs.o
diff --git a/fs/exofs/exofs.h b/fs/exofs/exofs.h
index 94047b9..b298c7a 100644
--- a/fs/exofs/exofs.h
+++ b/fs/exofs/exofs.h
@@ -56,6 +56,9 @@
 struct exofs_dev {
 	struct ore_dev ored;
 	unsigned did;
+	unsigned urilen;
+	uint8_t *uri;
+	struct kobject ed_kobj;
 };
 /*
  * our extension to the in-memory superblock
@@ -73,6 +76,7 @@ struct exofs_sb_info {
 	struct ore_layout	layout;		/* Default files layout       */
 	struct ore_comp one_comp;		/* id & cred of partition id=0*/
 	struct ore_components oc;		/* comps for the partition    */
+	struct kobject	s_kobj;			/* holds per-sbi kobject      */
 };
 
 /*
diff --git a/fs/exofs/export.c b/fs/exofs/export.c
index 621bd11..a53f575 100644
--- a/fs/exofs/export.c
+++ b/fs/exofs/export.c
@@ -321,6 +321,7 @@ int exofs_get_device_info(struct super_block *sb, struct exp_xdr_stream *xdr,
 {
 	struct exofs_sb_info *sbi = sb->s_fs_info;
 	struct pnfs_osd_deviceaddr devaddr;
+	struct exofs_dev *edev;
 	const struct osd_dev_info *odi;
 	u64 devno = devid->devid;
 	__be32 *start;
@@ -334,7 +335,8 @@ int exofs_get_device_info(struct super_block *sb, struct exp_xdr_stream *xdr,
 		return -ENODEV;
 	}
 
-	odi = osduld_device_info(sbi->oc.ods[devno]->od);
+	edev = container_of(sbi->oc.ods[devno], typeof(*edev), ored);
+	odi = osduld_device_info(edev->ored.od);
 
 	devaddr.oda_systemid.len = odi->systemid_len;
 	devaddr.oda_systemid.data = (void *)odi->systemid; /* !const cast */
@@ -342,6 +344,10 @@ int exofs_get_device_info(struct super_block *sb, struct exp_xdr_stream *xdr,
 	devaddr.oda_osdname.len = odi->osdname_len ;
 	devaddr.oda_osdname.data = (void *)odi->osdname;/* !const cast */
 
+	devaddr.oda_targetaddr.ota_available = OBJ_OTA_AVAILABLE;
+	devaddr.oda_targetaddr.ota_netaddr.r_addr.data = (void *)edev->uri;
+	devaddr.oda_targetaddr.ota_netaddr.r_addr.len = edev->urilen;
+
 	/* skip opaque size, will be filled-in later */
 	start = exp_xdr_reserve_qwords(xdr, 1);
 	if (!start) {
diff --git a/fs/exofs/super.c b/fs/exofs/super.c
index 3c0d83a..a4834f7 100644
--- a/fs/exofs/super.c
+++ b/fs/exofs/super.c
@@ -39,6 +39,7 @@
 #include <linux/exportfs.h>
 #include <linux/slab.h>
 
+#include "sys.h"
 #include "exofs.h"
 
 #define EXOFS_DBGMSG2(M...) do {} while (0)
@@ -472,6 +473,7 @@ static void exofs_put_super(struct super_block *sb)
 	_exofs_print_device("Unmounting", NULL, ore_comp_dev(&sbi->oc, 0),
 			    sbi->one_comp.obj.partition);
 
+	exofs_sysfs_cluster_del(sbi);
 	bdi_destroy(&sbi->bdi);
 	exofs_free_sbi(sbi);
 	sb->s_fs_info = NULL;
@@ -632,6 +634,11 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
 	memcpy(&sbi->oc.ods[numdevs], &sbi->oc.ods[0],
 		(numdevs - 1) * sizeof(sbi->oc.ods[0]));
 
+	/* create sysfs entries to hold the current exofs cluster instance.
+	 * There will be one sysfs dirent for cluster osdname per exofs mount
+	 */
+	exofs_sysfs_cluster_add(&dt->dt_dev_table[0], sbi);
+
 	for (i = 0; i < numdevs; i++) {
 		struct exofs_fscb fscb;
 		struct osd_dev_info odi;
@@ -657,6 +664,7 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
 			eds[i].ored.od = fscb_od;
 			++sbi->oc.numdevs;
 			fscb_od = NULL;
+			exofs_sysfs_odev_add(&eds[i], sbi);
 			continue;
 		}
 
@@ -682,6 +690,7 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
 				  odi.osdname);
 			goto out;
 		}
+		exofs_sysfs_odev_add(&eds[i], sbi);
 
 		/* TODO: verify other information is correct and FS-uuid
 		 *	 matches. Benny what did you say about device table
@@ -845,6 +854,7 @@ static int exofs_fill_super(struct super_block *sb, void *data, int silent)
 		goto free_sbi;
 	}
 
+	exofs_sysfs_print();
 	_exofs_print_device("Mounting", opts->dev_name,
 			    ore_comp_dev(&sbi->oc, 0),
 			    sbi->one_comp.obj.partition);
@@ -1024,6 +1034,9 @@ static int __init init_exofs(void)
 	if (err)
 		goto out_d;
 
+	/* We don't fail if sysfs creation failed */
+	exofs_sysfs_init();
+
 	return 0;
 out_d:
 	destroy_inodecache();
@@ -1033,6 +1046,7 @@ out:
 
 static void __exit exit_exofs(void)
 {
+	exofs_sysfs_uninit();
 	unregister_filesystem(&exofs_type);
 	destroy_inodecache();
 }
diff --git a/fs/exofs/sys.c b/fs/exofs/sys.c
new file mode 100644
index 0000000..17c9c07
--- /dev/null
+++ b/fs/exofs/sys.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2012
+ * Sachin Bhamare <sbhamare@panasas.com>
+ *
+ * This file is part of exofs.
+ *
+ * exofs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation.  Since it is based on ext2, and the only
+ * valid version of GPL for the Linux kernel is version 2, the only valid
+ * version of GPL for exofs is version 2.
+ *
+ * exofs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with exofs; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <linux/kobject.h>
+#include <linux/device.h>
+
+#include "sys.h"
+#include "exofs.h"
+
+struct odev_attr {
+	struct attribute attr;
+	ssize_t (*show)(struct exofs_dev *, char *);
+	ssize_t (*store)(struct exofs_dev *, const char *, size_t);
+};
+
+static ssize_t odev_attr_show(struct kobject *kobj, struct attribute *attr,
+		char *buf)
+{
+	struct exofs_dev *edp = container_of(kobj, struct exofs_dev, ed_kobj);
+	struct odev_attr *a = container_of(attr, struct odev_attr, attr);
+
+	return a->show ? a->show(edp, buf) : 0;
+}
+
+static ssize_t odev_attr_store(struct kobject *kobj, struct attribute *attr,
+		const char *buf, size_t len)
+{
+	struct exofs_dev *edp = container_of(kobj, struct exofs_dev, ed_kobj);
+	struct odev_attr *a = container_of(attr, struct odev_attr, attr);
+
+	return a->store ? a->store(edp, buf, len) : len;
+}
+
+static const struct sysfs_ops odev_attr_ops = {
+	.show  = odev_attr_show,
+	.store = odev_attr_store,
+};
+
+
+static struct kset *exofs_kset;
+
+static ssize_t osdname_show(struct exofs_dev *edp, char *buf)
+{
+	struct osd_dev *odev = edp->ored.od;
+	const struct osd_dev_info *odi = osduld_device_info(odev);
+
+	return snprintf(buf, odi->osdname_len + 1, "%s", odi->osdname);
+}
+
+static ssize_t systemid_show(struct exofs_dev *edp, char *buf)
+{
+	struct osd_dev *odev = edp->ored.od;
+	const struct osd_dev_info *odi = osduld_device_info(odev);
+
+	memcpy(buf, odi->systemid, odi->systemid_len);
+	return odi->systemid_len;
+}
+
+static ssize_t uri_show(struct exofs_dev *edp, char *buf)
+{
+	return snprintf(buf, edp->urilen, "%s", edp->uri);
+}
+
+static ssize_t uri_store(struct exofs_dev *edp, const char *buf, size_t len)
+{
+	edp->urilen = strlen(buf) + 1;
+	edp->uri = krealloc(edp->uri, edp->urilen, GFP_KERNEL);
+	strncpy(edp->uri, buf, edp->urilen);
+	return edp->urilen;
+}
+
+#define OSD_ATTR(name, mode, show, store) \
+	static struct odev_attr odev_attr_##name = \
+					__ATTR(name, mode, show, store)
+
+OSD_ATTR(osdname, S_IRUGO, osdname_show, NULL);
+OSD_ATTR(systemid, S_IRUGO, systemid_show, NULL);
+OSD_ATTR(uri, S_IRWXU, uri_show, uri_store);
+
+static struct attribute *odev_attrs[] = {
+	&odev_attr_osdname.attr,
+	&odev_attr_systemid.attr,
+	&odev_attr_uri.attr,
+	NULL,
+};
+
+static struct kobj_type odev_ktype = {
+	.default_attrs	= odev_attrs,
+	.sysfs_ops	= &odev_attr_ops,
+};
+
+static struct kobj_type uuid_ktype = {
+};
+
+void exofs_sysfs_print()
+{
+#ifdef CONFIG_EXOFS_DEBUG
+	struct kobject *k_name, *k_tmp;
+
+	list_for_each_entry_safe(k_name, k_tmp, &exofs_kset->list, entry) {
+		printk(KERN_INFO "%s: name %s ref %d\n",
+			__func__, kobject_name(k_name),
+			(int)atomic_read(&k_name->kref.refcount));
+	}
+#endif
+}
+/*
+ * This function removes all kobjects under exofs_kset
+ * At the end of it, exofs_kset kobject will have a refcount
+ * of 1 which gets decremented only on exofs module unload
+ */
+void exofs_sysfs_cluster_del(struct exofs_sb_info *sbi)
+{
+	struct kobject *k_name, *k_tmp;
+	struct kobject *s_kobj = &sbi->s_kobj;
+
+	list_for_each_entry_safe(k_name, k_tmp, &exofs_kset->list, entry) {
+		/* Remove all that are children of this SBI */
+		if (k_name->parent == s_kobj)
+			kobject_put(k_name);
+	}
+	kobject_put(s_kobj);
+}
+
+/*
+ * This function creates sysfs entries to hold the current exofs cluster
+ * instance (uniquely identified by osdname,pid tuple).
+ * This function gets called once per exofs mount instance.
+ */
+int exofs_sysfs_cluster_add(struct exofs_dt_device_info *dt_dev,
+		struct exofs_sb_info *sbi)
+{
+	struct kobject *s_kobj;
+	int retval = 0;
+	uint64_t pid = sbi->one_comp.obj.partition;
+
+	/* allocate new uuid dirent */
+	s_kobj = &sbi->s_kobj;
+	s_kobj->kset = exofs_kset;
+	retval = kobject_init_and_add(s_kobj, &uuid_ktype,
+			&exofs_kset->kobj,  "%s_%llx", dt_dev->osdname, pid);
+	if (retval) {
+		EXOFS_ERR("ERROR: Failed to create sysfs entry for "
+			"uuid-%s_%llx => %d\n", dt_dev->osdname, pid, retval);
+		return -ENOMEM;
+	}
+	return 0;
+}
+
+int exofs_sysfs_odev_add(struct exofs_dev *edev, struct exofs_sb_info *sbi)
+{
+	struct kobject *d_kobj;
+	int retval = 0;
+
+	/* create osd device group which contains following attributes
+	 * osdname, systemid & uri
+	 */
+	d_kobj = &edev->ed_kobj;
+	d_kobj->kset = exofs_kset;
+	retval = kobject_init_and_add(d_kobj, &odev_ktype,
+			&sbi->s_kobj, "dev%u", edev->did);
+	if (retval) {
+		EXOFS_ERR("ERROR: Failed to create sysfs entry for"
+				" device dev%u\n", edev->did);
+		return retval;
+	}
+	return 0;
+}
+
+int exofs_sysfs_init(void)
+{
+	exofs_kset = kset_create_and_add("exofs", NULL, fs_kobj);
+	if (!exofs_kset) {
+		EXOFS_ERR("ERROR: kset_create_and_add exofs failed\n");
+		return -ENOMEM;
+	}
+	return 0;
+}
+
+void exofs_sysfs_uninit(void)
+{
+	kset_unregister(exofs_kset);
+}
diff --git a/fs/exofs/sys.h b/fs/exofs/sys.h
new file mode 100644
index 0000000..cfabc1d
--- /dev/null
+++ b/fs/exofs/sys.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2012
+ * Sachin Bhamare <sbhamare@panasas.com>
+ *
+ * This file is part of exofs.
+ *
+ * exofs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation.  Since it is based on ext2, and the only
+ * valid version of GPL for the Linux kernel is version 2, the only valid
+ * version of GPL for exofs is version 2.
+ *
+ * exofs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with exofs; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __SYS_DOT_H__
+#define __SYS_DOT_H__
+
+struct exofs_dev;
+struct exofs_sb_info;
+struct exofs_dt_device_info;
+
+int exofs_sysfs_odev_add(struct exofs_dev *edev,
+			 struct exofs_sb_info *sbi);
+int exofs_sysfs_cluster_add(struct exofs_dt_device_info *dt_dev,
+		struct exofs_sb_info *sbi);
+void exofs_sysfs_cluster_del(struct exofs_sb_info *sbi);
+
+void exofs_sysfs_print(void);
+int exofs_sysfs_init(void);
+void exofs_sysfs_uninit(void);
+
+#endif /* __SYS_DOT_H__ */
+
diff --git a/fs/exportfs/pnfs_osd_xdr_srv.c b/fs/exportfs/pnfs_osd_xdr_srv.c
index 12a3bda..d0795c44 100644
--- a/fs/exportfs/pnfs_osd_xdr_srv.c
+++ b/fs/exportfs/pnfs_osd_xdr_srv.c
@@ -179,6 +179,42 @@ static enum nfsstat4 _encode_string(struct exp_xdr_stream *xdr,
 	return 0;
 }
 
+/* struct pnfs_osd_targetaddr {
+ *	u32				ota_available;
+ *	struct pnfs_osd_net_addr	ota_netaddr;
+ * };
+ */
+static inline enum nfsstat4 pnfs_osd_xdr_encode_targetaddr(
+	struct exp_xdr_stream *xdr,
+	struct pnfs_osd_targetaddr *taddr)
+{
+	__be32 *p;
+
+	/* ota_available */
+	p = exp_xdr_reserve_space(xdr, 4);
+	if (!p)
+		return NFS4ERR_TOOSMALL;
+	p = exp_xdr_encode_u32(p, taddr->ota_available);
+
+	/* encode r_netid */
+	p = exp_xdr_reserve_space(xdr, 4 + taddr->ota_netaddr.r_netid.len);
+	if (!p)
+		return NFS4ERR_TOOSMALL;
+
+	p = exp_xdr_encode_opaque(p,
+				taddr->ota_netaddr.r_netid.data,
+				taddr->ota_netaddr.r_netid.len);
+
+	/* encode r_addr */
+	p = exp_xdr_reserve_space(xdr, 4 + taddr->ota_netaddr.r_addr.len);
+	if (!p)
+		return NFS4ERR_TOOSMALL;
+	p = exp_xdr_encode_opaque(p,
+				taddr->ota_netaddr.r_addr.data,
+				taddr->ota_netaddr.r_addr.len);
+	return 0;
+}
+
 /* struct pnfs_osd_deviceaddr {
  *	struct pnfs_osd_targetid	oda_targetid;
  *	struct pnfs_osd_targetaddr	oda_targetaddr;
@@ -194,17 +230,20 @@ enum nfsstat4 pnfs_osd_xdr_encode_deviceaddr(
 	__be32 *p;
 	enum nfsstat4 err;
 
-	p = exp_xdr_reserve_space(xdr, 4 + 4 + sizeof(devaddr->oda_lun));
+	p = exp_xdr_reserve_space(xdr, sizeof(u32));
 	if (!p)
 		return NFS4ERR_TOOSMALL;
 
 	/* Empty oda_targetid */
 	p = exp_xdr_encode_u32(p, OBJ_TARGET_ANON);
 
-	/* Empty oda_targetaddr for now */
-	p = exp_xdr_encode_u32(p, 0);
+	/* oda_targetaddr */
+	err = pnfs_osd_xdr_encode_targetaddr(xdr, &devaddr->oda_targetaddr);
+	if (err)
+		return err;
 
 	/* oda_lun */
+	p = exp_xdr_reserve_space(xdr, sizeof(devaddr->oda_lun));
 	exp_xdr_encode_bytes(p, devaddr->oda_lun, sizeof(devaddr->oda_lun));
 
 	err = _encode_string(xdr, &devaddr->oda_systemid);
diff --git a/include/linux/pnfs_osd_xdr.h b/include/linux/pnfs_osd_xdr.h
index e0557c1..eeedf73 100644
--- a/include/linux/pnfs_osd_xdr.h
+++ b/include/linux/pnfs_osd_xdr.h
@@ -154,6 +154,11 @@ enum pnfs_osd_targetid_type {
 	OBJ_TARGET_SCSI_DEVICE_ID = 3,
 };
 
+enum pnfs_osd_target_ota {
+	OBJ_OTA_UNAVAILABLE = 0,
+	OBJ_OTA_AVAILABLE = 1,
+};
+
 /*   union pnfs_osd_targetid4 switch (pnfs_osd_targetid_type4 oti_type) {
  *       case OBJ_TARGET_SCSI_NAME:
  *           string              oti_scsi_name<>;
-- 
1.7.6.2



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/4] pnfs-obj: Remove unused variable from objlayout_get_deviceinfo().
  2012-03-16  6:17 [PATCHSET 0/4] Auto-login support for the pnfs-objects protocol Boaz Harrosh
  2012-03-16  6:19 ` [PATCH 1/4] pnfsd-exofs: Add autologin support to exofs Boaz Harrosh
@ 2012-03-16  6:21 ` Boaz Harrosh
  2012-03-16  6:23 ` [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin Boaz Harrosh
  2012-03-16  6:27 ` [PATCH 4/4] osd_login: Add autologin script for objlayoutdriver Boaz Harrosh
  3 siblings, 0 replies; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-16  6:21 UTC (permalink / raw)
  To: Boaz Harrosh, Trond Myklebust, NFS list, open-osd, Bhamare, Sachin
  Cc: Benny Halevy, Steve Dickson, Welch, Brent

From: Sachin Bhamare <sbhamare@panasas.com>

Local variable 'sb' was not being used in objlayout_get_deviceinfo().

Signed-off-by: Sachin Bhamare <sbhamare@panasas.com>
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
 fs/nfs/objlayout/objlayout.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/objlayout/objlayout.c b/fs/nfs/objlayout/objlayout.c
index b3c2903..71047c9 100644
--- a/fs/nfs/objlayout/objlayout.c
+++ b/fs/nfs/objlayout/objlayout.c
@@ -601,7 +601,6 @@ int objlayout_get_deviceinfo(struct pnfs_layout_hdr *pnfslay,
 {
 	struct objlayout_deviceinfo *odi;
 	struct pnfs_device pd;
-	struct super_block *sb;
 	struct page *page, **pages;
 	u32 *p;
 	int err;
@@ -620,7 +619,6 @@ int objlayout_get_deviceinfo(struct pnfs_layout_hdr *pnfslay,
 	pd.pglen = PAGE_SIZE;
 	pd.mincount = 0;
 
-	sb = pnfslay->plh_inode->i_sb;
 	err = nfs4_proc_getdeviceinfo(NFS_SERVER(pnfslay->plh_inode), &pd);
 	dprintk("%s nfs_getdeviceinfo returned %d\n", __func__, err);
 	if (err)
-- 
1.7.6.2



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin
  2012-03-16  6:17 [PATCHSET 0/4] Auto-login support for the pnfs-objects protocol Boaz Harrosh
  2012-03-16  6:19 ` [PATCH 1/4] pnfsd-exofs: Add autologin support to exofs Boaz Harrosh
  2012-03-16  6:21 ` [PATCH 2/4] pnfs-obj: Remove unused variable from objlayout_get_deviceinfo() Boaz Harrosh
@ 2012-03-16  6:23 ` Boaz Harrosh
  2012-03-16 21:40   ` Myklebust, Trond
  2012-03-20  3:47   ` [PATCH version2] " Boaz Harrosh
  2012-03-16  6:27 ` [PATCH 4/4] osd_login: Add autologin script for objlayoutdriver Boaz Harrosh
  3 siblings, 2 replies; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-16  6:23 UTC (permalink / raw)
  To: Boaz Harrosh, Trond Myklebust, NFS list, open-osd, Bhamare, Sachin
  Cc: Benny Halevy, Steve Dickson, Welch, Brent

From: Sachin Bhamare <sbhamare@panasas.com>

The pnfs-objects protocol mandates that we autologin into devices not
present in the system, according to information specified in the
get_device_info returned from the server.

The Protocol specifies two login hints.
1. An IP address:port combination
2. A string URI which is constructed as a URL with a protocol prefix
   followed by :// and a string as address. For each  protocol prefix
   the string-address format might be different.

We only support the second option. The first option is just redundant
to the second one.
NOTE: The Kernel part of autologin does not parse the URI string. It
just channels it to a user-mode script. So any new login protocols should
only update the user-mode script which is a part of the nfs-utils package,
but the Kernel need not change.

We implement the autologin by using the call_usermodehelper() API.
(Thanks to Steve Dickson <steved@redhat.com> for pointing it out)
So there is no running daemon needed, and or special setup.

All is needed is that "/sbin/osd_login" script exists.
TODO:
  "osd_login" is an hard coded name. If not present we will rate_limit
  print to dmsg and keep failing. In such cases we should stop trying
  and provide sysfs interface for re-enabling autologin. For example,
  we could ZERO out the script name and let user-mode set a new script
  name.
  [Q] Where in sysfs should a layout-driver put its things?

Signed-off-by: Sachin Bhamare <sbhamare@panasas.com>
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
 fs/nfs/objlayout/objio_osd.c |    9 +++
 fs/nfs/objlayout/objlayout.c |  120 ++++++++++++++++++++++++++++++++++++++++++
 fs/nfs/objlayout/objlayout.h |    2 +
 3 files changed, 131 insertions(+), 0 deletions(-)

diff --git a/fs/nfs/objlayout/objio_osd.c b/fs/nfs/objlayout/objio_osd.c
index 37a9269..5b2ac9e 100644
--- a/fs/nfs/objlayout/objio_osd.c
+++ b/fs/nfs/objlayout/objio_osd.c
@@ -137,6 +137,7 @@ static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
 	struct objio_dev_ent *ode;
 	struct osd_dev *od;
 	struct osd_dev_info odi;
+	bool retry_flag = true;
 	int err;
 
 	ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id);
@@ -171,10 +172,18 @@ static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
 		goto out;
 	}
 
+retry_lookup:
 	od = osduld_info_lookup(&odi);
 	if (unlikely(IS_ERR(od))) {
 		err = PTR_ERR(od);
 		dprintk("%s: osduld_info_lookup => %d\n", __func__, err);
+		if (err == -ENODEV && retry_flag) {
+			err = objlayout_autologin(deviceaddr);
+			if (likely(!err)) {
+				retry_flag = false;
+				goto retry_lookup;
+			}
+		}
 		goto out;
 	}
 
diff --git a/fs/nfs/objlayout/objlayout.c b/fs/nfs/objlayout/objlayout.c
index 71047c9..d953948 100644
--- a/fs/nfs/objlayout/objlayout.c
+++ b/fs/nfs/objlayout/objlayout.c
@@ -37,6 +37,8 @@
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <linux/kmod.h>
+#include <linux/ratelimit.h>
 #include <scsi/osd_initiator.h>
 #include "objlayout.h"
 
@@ -649,3 +651,121 @@ void objlayout_put_deviceinfo(struct pnfs_osd_deviceaddr *deviceaddr)
 	__free_page(odi->page);
 	kfree(odi);
 }
+
+static const char osd_login_prog[] = "/sbin/osd_login";
+
+enum {
+	OBJLAYOUT_MAX_URI_LEN = 256, OBJLAYOUT_MAX_OSDNAME_LEN = 64,
+	OBJLAYOUT_MAX_SYSID_HEX_LEN = OSD_SYSTEMID_LEN * 2 + 1,
+};
+
+struct __auto_login {
+	char uri[OBJLAYOUT_MAX_URI_LEN];
+	char osdname[OBJLAYOUT_MAX_OSDNAME_LEN];
+	char systemid_hex[OBJLAYOUT_MAX_SYSID_HEX_LEN];
+};
+
+static int __objlayout_upcall(struct __auto_login *login)
+{
+	static char *envp[] = { "HOME=/root",
+		"TERM=linux",
+		"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
+		NULL
+	};
+	char *argv[8];
+	int ret;
+
+	dprintk("%s uri: %s\n", __func__, login->uri);
+	dprintk("%s osdname %s\n", __func__, login->osdname);
+	dprintk("%s systemid_hex %s\n", __func__, login->systemid_hex);
+
+	argv[0] = (char *)osd_login_prog;
+	argv[1] = "-u";
+	argv[2] = login->uri;
+	argv[3] = "-o";
+	argv[4] = login->osdname;
+	argv[5] = "-s";
+	argv[6] = login->systemid_hex;
+	argv[7] = NULL;
+
+	ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
+	/*
+	 * TODO: Disable the upcall mechanism if we're getting an ENOENT or
+	 * EACCES error. The admin can re-enable it on the fly by using
+	 * sysfs to set the parameter once the problem has been fixed.
+	 */
+	if (ret == -ENOENT || ret == -EACCES)
+		pr_warn_ratelimited("PNFS-OBJ:: %s: %s "
+			"was not found please install new nfs-utils pkg!\n",
+			__func__, osd_login_prog);
+	dprintk("%s %s return value: %d\n", __func__, osd_login_prog, ret);
+
+	return ret;
+}
+
+/* Assume dest is all zeros */
+static void __copy_nfsS_and_zero_terminate(struct nfs4_string s,
+					   char *dest, int max_len,
+					   const char *var_name)
+{
+	if (!s.len)
+		return;
+
+	if (s.len >= max_len) {
+		pr_warn_ratelimited(
+			"objlayout_autologin: %s: s.len(%d) >= max_len(%d)",
+			var_name, s.len, max_len);
+		s.len = max_len - 1; /* space for null terminator */
+	}
+
+	memcpy(dest, s.data, s.len);
+}
+
+/* Assume sysid is all zeros */
+static void _sysid_2_hex(struct nfs4_string s,
+		  char sysid[OBJLAYOUT_MAX_SYSID_HEX_LEN])
+{
+	int i;
+	char *cur;
+
+	if (!s.len)
+		return;
+
+	if (s.len != OSD_SYSTEMID_LEN) {
+		pr_warn_ratelimited(
+		    "objlayout_autologin: systemid_len(%d) != OSD_SYSTEMID_LEN",
+		    s.len);
+		if (s.len > OSD_SYSTEMID_LEN)
+			s.len = OSD_SYSTEMID_LEN;
+	}
+
+	cur = sysid;
+	for (i = 0; i < s.len; i++)
+		cur = hex_byte_pack(cur, s.data[i]);
+}
+
+int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr)
+{
+	int rc;
+	struct __auto_login login;
+
+	if (!deviceaddr->oda_targetaddr.ota_netaddr.r_addr.len)
+		return -ENODEV;
+
+	memset(&login, 0, sizeof(login));
+	__copy_nfsS_and_zero_terminate(
+		deviceaddr->oda_targetaddr.ota_netaddr.r_addr,
+		login.uri, sizeof(login.uri), "URI");
+
+	__copy_nfsS_and_zero_terminate(
+		deviceaddr->oda_osdname,
+		login.osdname, sizeof(login.osdname), "OSDNAME");
+
+	_sysid_2_hex(deviceaddr->oda_systemid, login.systemid_hex);
+
+	rc = __objlayout_upcall(&login);
+	if (rc > 0) /* script returns positive values */
+		rc = -ENODEV;
+
+	return rc;
+}
diff --git a/fs/nfs/objlayout/objlayout.h b/fs/nfs/objlayout/objlayout.h
index 8ec3472..880ba08 100644
--- a/fs/nfs/objlayout/objlayout.h
+++ b/fs/nfs/objlayout/objlayout.h
@@ -184,4 +184,6 @@ extern void objlayout_encode_layoutreturn(
 	struct xdr_stream *,
 	const struct nfs4_layoutreturn_args *);
 
+extern int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr);
+
 #endif /* _OBJLAYOUT_H */
-- 
1.7.6.2



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 4/4] osd_login: Add autologin script for objlayoutdriver
  2012-03-16  6:17 [PATCHSET 0/4] Auto-login support for the pnfs-objects protocol Boaz Harrosh
                   ` (2 preceding siblings ...)
  2012-03-16  6:23 ` [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin Boaz Harrosh
@ 2012-03-16  6:27 ` Boaz Harrosh
  2012-03-23  2:36   ` SQUASHME: " Boaz Harrosh
                     ` (2 more replies)
  3 siblings, 3 replies; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-16  6:27 UTC (permalink / raw)
  To: Boaz Harrosh, Steve Dickson, NFS list, open-osd, Bhamare, Sachin
  Cc: Trond Myklebust, Benny Halevy, Welch, Brent

From: Sachin Bhamare <sbhamare@panasas.com>

This script is part of the autologin feature mandated by the
pnfs-objects standard.
It is called from objlayoutdriver.ko in the kernel.

Signed-off-by: Sachin Bhamare <sbhamare@panasas.com>
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
 configure.ac                |    1 +
 utils/Makefile.am           |    1 +
 utils/osd_login/Makefile.am |   13 +++++
 utils/osd_login/osd_login   |  102 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 117 insertions(+), 0 deletions(-)
 create mode 100644 utils/osd_login/Makefile.am
 create mode 100755 utils/osd_login/osd_login

diff --git a/configure.ac b/configure.ac
index 67e8d2d..011a2bf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -467,6 +467,7 @@ AC_CONFIG_FILES([
 	utils/nfsidmap/Makefile
 	utils/showmount/Makefile
 	utils/statd/Makefile
+	utils/osd_login/Makefile
 	tests/Makefile
 	tests/nsm_client/Makefile])
 AC_OUTPUT
diff --git a/utils/Makefile.am b/utils/Makefile.am
index d074b85..c7e5d27 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -28,6 +28,7 @@ SUBDIRS = \
 	nfsstat \
 	showmount \
 	statd \
+	osd_login \
 	$(OPTDIRS)
 
 MAINTAINERCLEANFILES = Makefile.in
diff --git a/utils/osd_login/Makefile.am b/utils/osd_login/Makefile.am
new file mode 100644
index 0000000..e931e36
--- /dev/null
+++ b/utils/osd_login/Makefile.am
@@ -0,0 +1,13 @@
+## Process this file with automake to produce Makefile.in
+
+OSD_LOGIN_FILES= osd_login
+
+EXTRA_DIST= $(OSD_LOGIN_FILES)
+
+all-local: $(OSD_LOGIN_FILES)
+
+install-data-hook:
+	$(INSTALL) --mode 755 osd_login $(DESTDIR)/sbin/osd_login
+
+MAINTAINERCLEANFILES = Makefile.in
+
diff --git a/utils/osd_login/osd_login b/utils/osd_login/osd_login
new file mode 100755
index 0000000..161a487
--- /dev/null
+++ b/utils/osd_login/osd_login
@@ -0,0 +1,102 @@
+#!/bin/bash
+#
+# osd_login : This script is part of the autologin feature
+#             mandated by the pnfs-objects standard.
+# It is called from objlayoutdriver.ko in the kernel.
+
+# Copyright (C) 2012, Sachin Bhamare <sbhamare@panasas.com>
+# Copyright (C) 2012, Boaz Harrosh <bharrosh@panasas.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301 USA
+
+umask 022
+
+PATH="/sbin:/usr/sbin:/bin:/usr/bin"
+
+iscsiadm=/sbin/iscsiadm
+
+protocol=""
+portal=""
+uri=""
+osdname=""
+systemid=""
+
+usage()
+{
+	echo "Usage: $0 -u <URI> -o <OSDNAME> -s <SYSTEMID>"
+	echo "Options:"
+	echo  "-u		target uri e.g. iscsi://<ip>:<port>"
+	echo  "-o		osdname of the target OSD"
+	echo  "-s 		systemid of the target OSD"
+}
+
+parse_cmdline()
+{
+	argc=$#
+	if [ $# -lt 3 ]; then
+		usage
+		exit 1
+	fi
+
+	# parse the input arguments
+	while getopts "u:o:s:" options; do
+	    case $options in
+		u ) uri=$OPTARG;;
+		o ) osdname=$OPTARG;;
+		s ) systemid=$OPTARG;;
+		\? ) usage
+			exit 1;;
+		* )  usage
+			exit 1;;
+	    esac
+	done
+
+	echo "-u : $uri"
+	echo "-o : $osdname"
+	echo "-s : $systemid"
+
+	protocol=`echo $uri | awk -F ':' '{print $1}'`
+	portal=`echo $uri | awk -F '//' '{print $2}'`
+}
+
+do_cmd()
+{
+	$* 2>&1 | logger &
+}
+
+login_iscsi_osd()
+{
+	echo "osd_login: login into: $1"
+	if ! $iscsiadm -m discovery -o nonpersistent -t sendtargets -p $1 --login; then
+		echo "$iscsiadm -m discovery -t sendtargets -p $1 --login returned error $? !"
+		sleep 1;
+	fi
+}
+
+ echo "============= osd_login ========="
+ echo "progname : $0"
+parse_cmdline "$@"
+echo "protocol: $protocol"
+echo "portal: $portal"
+
+case $protocol in
+iscsi)
+	login_iscsi_osd $portal |& logger
+	;;
+*)
+	echo "osd_login: Error: protocol $protocol not supported !" | logger
+	;;
+esac
+
-- 
1.7.6.2



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/4] pnfsd-exofs:  Add autologin support to exofs
  2012-03-16  6:19 ` [PATCH 1/4] pnfsd-exofs: Add autologin support to exofs Boaz Harrosh
@ 2012-03-16  6:30   ` Boaz Harrosh
  0 siblings, 0 replies; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-16  6:30 UTC (permalink / raw)
  To: Boaz Harrosh
  Cc: Trond Myklebust, Benny Halevy, NFS list, open-osd, Bhamare,
	Sachin, Steve Dickson, Welch, Brent

On 03/15/2012 11:19 PM, Boaz Harrosh wrote:
> 

Hi Benny I made a mistake with this one it is actually:

From: Sachin Bhamare <sbhamare@panasas.com>

Eventually we'll fix this. please also do so in your
tree.

Thanks
Boaz

> Introduce sysfs infrastructure for exofs cluster filesystem.
> 
> Each OSD target shows up as below in the sysfs hierarchy:
> 	/sys/fs/exofs/<osdname>_<partition_id>/devX
> 
> where in devX 0 <= X < device_table_size. They are ordered
> in device-table order as specified to the mkfs.exofs command
> 
> Each OSD device  devX has following attributes :
> 	osdname - ReadOnly
> 	systemid - ReadOnly
> 	uri - Read/Write
> 
> It is up to user-mode to update devX/uri for support of
> autologin.
> 
> Also fixed is the xdr encoding of device_info to support
> uri encoding.
> 
> Signed-off-by: Sachin Bhamare <sbhamare@panasas.com>
> Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
> ---
>  fs/exofs/Kbuild                |    2 +-
>  fs/exofs/exofs.h               |    4 +
>  fs/exofs/export.c              |    8 ++-
>  fs/exofs/super.c               |   14 +++
>  fs/exofs/sys.c                 |  202 ++++++++++++++++++++++++++++++++++++++++
>  fs/exofs/sys.h                 |   41 ++++++++
>  fs/exportfs/pnfs_osd_xdr_srv.c |   45 ++++++++-
>  include/linux/pnfs_osd_xdr.h   |    5 +
>  8 files changed, 316 insertions(+), 5 deletions(-)
>  create mode 100644 fs/exofs/sys.c
>  create mode 100644 fs/exofs/sys.h
> 
> diff --git a/fs/exofs/Kbuild b/fs/exofs/Kbuild
> index 1118068..5f6f1eb 100644
> --- a/fs/exofs/Kbuild
> +++ b/fs/exofs/Kbuild
> @@ -16,6 +16,6 @@
>  libore-y := ore.o ore_raid.o
>  obj-$(CONFIG_ORE) += libore.o
>  
> -exofs-y := inode.o file.o symlink.o namei.o dir.o super.o
> +exofs-y := inode.o file.o symlink.o namei.o dir.o super.o sys.o
>  exofs-$(CONFIG_PNFSD) +=  export.o
>  obj-$(CONFIG_EXOFS_FS) += exofs.o
> diff --git a/fs/exofs/exofs.h b/fs/exofs/exofs.h
> index 94047b9..b298c7a 100644
> --- a/fs/exofs/exofs.h
> +++ b/fs/exofs/exofs.h
> @@ -56,6 +56,9 @@
>  struct exofs_dev {
>  	struct ore_dev ored;
>  	unsigned did;
> +	unsigned urilen;
> +	uint8_t *uri;
> +	struct kobject ed_kobj;
>  };
>  /*
>   * our extension to the in-memory superblock
> @@ -73,6 +76,7 @@ struct exofs_sb_info {
>  	struct ore_layout	layout;		/* Default files layout       */
>  	struct ore_comp one_comp;		/* id & cred of partition id=0*/
>  	struct ore_components oc;		/* comps for the partition    */
> +	struct kobject	s_kobj;			/* holds per-sbi kobject      */
>  };
>  
>  /*
> diff --git a/fs/exofs/export.c b/fs/exofs/export.c
> index 621bd11..a53f575 100644
> --- a/fs/exofs/export.c
> +++ b/fs/exofs/export.c
> @@ -321,6 +321,7 @@ int exofs_get_device_info(struct super_block *sb, struct exp_xdr_stream *xdr,
>  {
>  	struct exofs_sb_info *sbi = sb->s_fs_info;
>  	struct pnfs_osd_deviceaddr devaddr;
> +	struct exofs_dev *edev;
>  	const struct osd_dev_info *odi;
>  	u64 devno = devid->devid;
>  	__be32 *start;
> @@ -334,7 +335,8 @@ int exofs_get_device_info(struct super_block *sb, struct exp_xdr_stream *xdr,
>  		return -ENODEV;
>  	}
>  
> -	odi = osduld_device_info(sbi->oc.ods[devno]->od);
> +	edev = container_of(sbi->oc.ods[devno], typeof(*edev), ored);
> +	odi = osduld_device_info(edev->ored.od);
>  
>  	devaddr.oda_systemid.len = odi->systemid_len;
>  	devaddr.oda_systemid.data = (void *)odi->systemid; /* !const cast */
> @@ -342,6 +344,10 @@ int exofs_get_device_info(struct super_block *sb, struct exp_xdr_stream *xdr,
>  	devaddr.oda_osdname.len = odi->osdname_len ;
>  	devaddr.oda_osdname.data = (void *)odi->osdname;/* !const cast */
>  
> +	devaddr.oda_targetaddr.ota_available = OBJ_OTA_AVAILABLE;
> +	devaddr.oda_targetaddr.ota_netaddr.r_addr.data = (void *)edev->uri;
> +	devaddr.oda_targetaddr.ota_netaddr.r_addr.len = edev->urilen;
> +
>  	/* skip opaque size, will be filled-in later */
>  	start = exp_xdr_reserve_qwords(xdr, 1);
>  	if (!start) {
> diff --git a/fs/exofs/super.c b/fs/exofs/super.c
> index 3c0d83a..a4834f7 100644
> --- a/fs/exofs/super.c
> +++ b/fs/exofs/super.c
> @@ -39,6 +39,7 @@
>  #include <linux/exportfs.h>
>  #include <linux/slab.h>
>  
> +#include "sys.h"
>  #include "exofs.h"
>  
>  #define EXOFS_DBGMSG2(M...) do {} while (0)
> @@ -472,6 +473,7 @@ static void exofs_put_super(struct super_block *sb)
>  	_exofs_print_device("Unmounting", NULL, ore_comp_dev(&sbi->oc, 0),
>  			    sbi->one_comp.obj.partition);
>  
> +	exofs_sysfs_cluster_del(sbi);
>  	bdi_destroy(&sbi->bdi);
>  	exofs_free_sbi(sbi);
>  	sb->s_fs_info = NULL;
> @@ -632,6 +634,11 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
>  	memcpy(&sbi->oc.ods[numdevs], &sbi->oc.ods[0],
>  		(numdevs - 1) * sizeof(sbi->oc.ods[0]));
>  
> +	/* create sysfs entries to hold the current exofs cluster instance.
> +	 * There will be one sysfs dirent for cluster osdname per exofs mount
> +	 */
> +	exofs_sysfs_cluster_add(&dt->dt_dev_table[0], sbi);
> +
>  	for (i = 0; i < numdevs; i++) {
>  		struct exofs_fscb fscb;
>  		struct osd_dev_info odi;
> @@ -657,6 +664,7 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
>  			eds[i].ored.od = fscb_od;
>  			++sbi->oc.numdevs;
>  			fscb_od = NULL;
> +			exofs_sysfs_odev_add(&eds[i], sbi);
>  			continue;
>  		}
>  
> @@ -682,6 +690,7 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
>  				  odi.osdname);
>  			goto out;
>  		}
> +		exofs_sysfs_odev_add(&eds[i], sbi);
>  
>  		/* TODO: verify other information is correct and FS-uuid
>  		 *	 matches. Benny what did you say about device table
> @@ -845,6 +854,7 @@ static int exofs_fill_super(struct super_block *sb, void *data, int silent)
>  		goto free_sbi;
>  	}
>  
> +	exofs_sysfs_print();
>  	_exofs_print_device("Mounting", opts->dev_name,
>  			    ore_comp_dev(&sbi->oc, 0),
>  			    sbi->one_comp.obj.partition);
> @@ -1024,6 +1034,9 @@ static int __init init_exofs(void)
>  	if (err)
>  		goto out_d;
>  
> +	/* We don't fail if sysfs creation failed */
> +	exofs_sysfs_init();
> +
>  	return 0;
>  out_d:
>  	destroy_inodecache();
> @@ -1033,6 +1046,7 @@ out:
>  
>  static void __exit exit_exofs(void)
>  {
> +	exofs_sysfs_uninit();
>  	unregister_filesystem(&exofs_type);
>  	destroy_inodecache();
>  }
> diff --git a/fs/exofs/sys.c b/fs/exofs/sys.c
> new file mode 100644
> index 0000000..17c9c07
> --- /dev/null
> +++ b/fs/exofs/sys.c
> @@ -0,0 +1,202 @@
> +/*
> + * Copyright (C) 2012
> + * Sachin Bhamare <sbhamare@panasas.com>
> + *
> + * This file is part of exofs.
> + *
> + * exofs is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation.  Since it is based on ext2, and the only
> + * valid version of GPL for the Linux kernel is version 2, the only valid
> + * version of GPL for exofs is version 2.
> + *
> + * exofs is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with exofs; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + */
> +
> +#include <linux/kobject.h>
> +#include <linux/device.h>
> +
> +#include "sys.h"
> +#include "exofs.h"
> +
> +struct odev_attr {
> +	struct attribute attr;
> +	ssize_t (*show)(struct exofs_dev *, char *);
> +	ssize_t (*store)(struct exofs_dev *, const char *, size_t);
> +};
> +
> +static ssize_t odev_attr_show(struct kobject *kobj, struct attribute *attr,
> +		char *buf)
> +{
> +	struct exofs_dev *edp = container_of(kobj, struct exofs_dev, ed_kobj);
> +	struct odev_attr *a = container_of(attr, struct odev_attr, attr);
> +
> +	return a->show ? a->show(edp, buf) : 0;
> +}
> +
> +static ssize_t odev_attr_store(struct kobject *kobj, struct attribute *attr,
> +		const char *buf, size_t len)
> +{
> +	struct exofs_dev *edp = container_of(kobj, struct exofs_dev, ed_kobj);
> +	struct odev_attr *a = container_of(attr, struct odev_attr, attr);
> +
> +	return a->store ? a->store(edp, buf, len) : len;
> +}
> +
> +static const struct sysfs_ops odev_attr_ops = {
> +	.show  = odev_attr_show,
> +	.store = odev_attr_store,
> +};
> +
> +
> +static struct kset *exofs_kset;
> +
> +static ssize_t osdname_show(struct exofs_dev *edp, char *buf)
> +{
> +	struct osd_dev *odev = edp->ored.od;
> +	const struct osd_dev_info *odi = osduld_device_info(odev);
> +
> +	return snprintf(buf, odi->osdname_len + 1, "%s", odi->osdname);
> +}
> +
> +static ssize_t systemid_show(struct exofs_dev *edp, char *buf)
> +{
> +	struct osd_dev *odev = edp->ored.od;
> +	const struct osd_dev_info *odi = osduld_device_info(odev);
> +
> +	memcpy(buf, odi->systemid, odi->systemid_len);
> +	return odi->systemid_len;
> +}
> +
> +static ssize_t uri_show(struct exofs_dev *edp, char *buf)
> +{
> +	return snprintf(buf, edp->urilen, "%s", edp->uri);
> +}
> +
> +static ssize_t uri_store(struct exofs_dev *edp, const char *buf, size_t len)
> +{
> +	edp->urilen = strlen(buf) + 1;
> +	edp->uri = krealloc(edp->uri, edp->urilen, GFP_KERNEL);
> +	strncpy(edp->uri, buf, edp->urilen);
> +	return edp->urilen;
> +}
> +
> +#define OSD_ATTR(name, mode, show, store) \
> +	static struct odev_attr odev_attr_##name = \
> +					__ATTR(name, mode, show, store)
> +
> +OSD_ATTR(osdname, S_IRUGO, osdname_show, NULL);
> +OSD_ATTR(systemid, S_IRUGO, systemid_show, NULL);
> +OSD_ATTR(uri, S_IRWXU, uri_show, uri_store);
> +
> +static struct attribute *odev_attrs[] = {
> +	&odev_attr_osdname.attr,
> +	&odev_attr_systemid.attr,
> +	&odev_attr_uri.attr,
> +	NULL,
> +};
> +
> +static struct kobj_type odev_ktype = {
> +	.default_attrs	= odev_attrs,
> +	.sysfs_ops	= &odev_attr_ops,
> +};
> +
> +static struct kobj_type uuid_ktype = {
> +};
> +
> +void exofs_sysfs_print()
> +{
> +#ifdef CONFIG_EXOFS_DEBUG
> +	struct kobject *k_name, *k_tmp;
> +
> +	list_for_each_entry_safe(k_name, k_tmp, &exofs_kset->list, entry) {
> +		printk(KERN_INFO "%s: name %s ref %d\n",
> +			__func__, kobject_name(k_name),
> +			(int)atomic_read(&k_name->kref.refcount));
> +	}
> +#endif
> +}
> +/*
> + * This function removes all kobjects under exofs_kset
> + * At the end of it, exofs_kset kobject will have a refcount
> + * of 1 which gets decremented only on exofs module unload
> + */
> +void exofs_sysfs_cluster_del(struct exofs_sb_info *sbi)
> +{
> +	struct kobject *k_name, *k_tmp;
> +	struct kobject *s_kobj = &sbi->s_kobj;
> +
> +	list_for_each_entry_safe(k_name, k_tmp, &exofs_kset->list, entry) {
> +		/* Remove all that are children of this SBI */
> +		if (k_name->parent == s_kobj)
> +			kobject_put(k_name);
> +	}
> +	kobject_put(s_kobj);
> +}
> +
> +/*
> + * This function creates sysfs entries to hold the current exofs cluster
> + * instance (uniquely identified by osdname,pid tuple).
> + * This function gets called once per exofs mount instance.
> + */
> +int exofs_sysfs_cluster_add(struct exofs_dt_device_info *dt_dev,
> +		struct exofs_sb_info *sbi)
> +{
> +	struct kobject *s_kobj;
> +	int retval = 0;
> +	uint64_t pid = sbi->one_comp.obj.partition;
> +
> +	/* allocate new uuid dirent */
> +	s_kobj = &sbi->s_kobj;
> +	s_kobj->kset = exofs_kset;
> +	retval = kobject_init_and_add(s_kobj, &uuid_ktype,
> +			&exofs_kset->kobj,  "%s_%llx", dt_dev->osdname, pid);
> +	if (retval) {
> +		EXOFS_ERR("ERROR: Failed to create sysfs entry for "
> +			"uuid-%s_%llx => %d\n", dt_dev->osdname, pid, retval);
> +		return -ENOMEM;
> +	}
> +	return 0;
> +}
> +
> +int exofs_sysfs_odev_add(struct exofs_dev *edev, struct exofs_sb_info *sbi)
> +{
> +	struct kobject *d_kobj;
> +	int retval = 0;
> +
> +	/* create osd device group which contains following attributes
> +	 * osdname, systemid & uri
> +	 */
> +	d_kobj = &edev->ed_kobj;
> +	d_kobj->kset = exofs_kset;
> +	retval = kobject_init_and_add(d_kobj, &odev_ktype,
> +			&sbi->s_kobj, "dev%u", edev->did);
> +	if (retval) {
> +		EXOFS_ERR("ERROR: Failed to create sysfs entry for"
> +				" device dev%u\n", edev->did);
> +		return retval;
> +	}
> +	return 0;
> +}
> +
> +int exofs_sysfs_init(void)
> +{
> +	exofs_kset = kset_create_and_add("exofs", NULL, fs_kobj);
> +	if (!exofs_kset) {
> +		EXOFS_ERR("ERROR: kset_create_and_add exofs failed\n");
> +		return -ENOMEM;
> +	}
> +	return 0;
> +}
> +
> +void exofs_sysfs_uninit(void)
> +{
> +	kset_unregister(exofs_kset);
> +}
> diff --git a/fs/exofs/sys.h b/fs/exofs/sys.h
> new file mode 100644
> index 0000000..cfabc1d
> --- /dev/null
> +++ b/fs/exofs/sys.h
> @@ -0,0 +1,41 @@
> +/*
> + * Copyright (C) 2012
> + * Sachin Bhamare <sbhamare@panasas.com>
> + *
> + * This file is part of exofs.
> + *
> + * exofs is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation.  Since it is based on ext2, and the only
> + * valid version of GPL for the Linux kernel is version 2, the only valid
> + * version of GPL for exofs is version 2.
> + *
> + * exofs is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with exofs; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + */
> +
> +#ifndef __SYS_DOT_H__
> +#define __SYS_DOT_H__
> +
> +struct exofs_dev;
> +struct exofs_sb_info;
> +struct exofs_dt_device_info;
> +
> +int exofs_sysfs_odev_add(struct exofs_dev *edev,
> +			 struct exofs_sb_info *sbi);
> +int exofs_sysfs_cluster_add(struct exofs_dt_device_info *dt_dev,
> +		struct exofs_sb_info *sbi);
> +void exofs_sysfs_cluster_del(struct exofs_sb_info *sbi);
> +
> +void exofs_sysfs_print(void);
> +int exofs_sysfs_init(void);
> +void exofs_sysfs_uninit(void);
> +
> +#endif /* __SYS_DOT_H__ */
> +
> diff --git a/fs/exportfs/pnfs_osd_xdr_srv.c b/fs/exportfs/pnfs_osd_xdr_srv.c
> index 12a3bda..d0795c44 100644
> --- a/fs/exportfs/pnfs_osd_xdr_srv.c
> +++ b/fs/exportfs/pnfs_osd_xdr_srv.c
> @@ -179,6 +179,42 @@ static enum nfsstat4 _encode_string(struct exp_xdr_stream *xdr,
>  	return 0;
>  }
>  
> +/* struct pnfs_osd_targetaddr {
> + *	u32				ota_available;
> + *	struct pnfs_osd_net_addr	ota_netaddr;
> + * };
> + */
> +static inline enum nfsstat4 pnfs_osd_xdr_encode_targetaddr(
> +	struct exp_xdr_stream *xdr,
> +	struct pnfs_osd_targetaddr *taddr)
> +{
> +	__be32 *p;
> +
> +	/* ota_available */
> +	p = exp_xdr_reserve_space(xdr, 4);
> +	if (!p)
> +		return NFS4ERR_TOOSMALL;
> +	p = exp_xdr_encode_u32(p, taddr->ota_available);
> +
> +	/* encode r_netid */
> +	p = exp_xdr_reserve_space(xdr, 4 + taddr->ota_netaddr.r_netid.len);
> +	if (!p)
> +		return NFS4ERR_TOOSMALL;
> +
> +	p = exp_xdr_encode_opaque(p,
> +				taddr->ota_netaddr.r_netid.data,
> +				taddr->ota_netaddr.r_netid.len);
> +
> +	/* encode r_addr */
> +	p = exp_xdr_reserve_space(xdr, 4 + taddr->ota_netaddr.r_addr.len);
> +	if (!p)
> +		return NFS4ERR_TOOSMALL;
> +	p = exp_xdr_encode_opaque(p,
> +				taddr->ota_netaddr.r_addr.data,
> +				taddr->ota_netaddr.r_addr.len);
> +	return 0;
> +}
> +
>  /* struct pnfs_osd_deviceaddr {
>   *	struct pnfs_osd_targetid	oda_targetid;
>   *	struct pnfs_osd_targetaddr	oda_targetaddr;
> @@ -194,17 +230,20 @@ enum nfsstat4 pnfs_osd_xdr_encode_deviceaddr(
>  	__be32 *p;
>  	enum nfsstat4 err;
>  
> -	p = exp_xdr_reserve_space(xdr, 4 + 4 + sizeof(devaddr->oda_lun));
> +	p = exp_xdr_reserve_space(xdr, sizeof(u32));
>  	if (!p)
>  		return NFS4ERR_TOOSMALL;
>  
>  	/* Empty oda_targetid */
>  	p = exp_xdr_encode_u32(p, OBJ_TARGET_ANON);
>  
> -	/* Empty oda_targetaddr for now */
> -	p = exp_xdr_encode_u32(p, 0);
> +	/* oda_targetaddr */
> +	err = pnfs_osd_xdr_encode_targetaddr(xdr, &devaddr->oda_targetaddr);
> +	if (err)
> +		return err;
>  
>  	/* oda_lun */
> +	p = exp_xdr_reserve_space(xdr, sizeof(devaddr->oda_lun));
>  	exp_xdr_encode_bytes(p, devaddr->oda_lun, sizeof(devaddr->oda_lun));
>  
>  	err = _encode_string(xdr, &devaddr->oda_systemid);
> diff --git a/include/linux/pnfs_osd_xdr.h b/include/linux/pnfs_osd_xdr.h
> index e0557c1..eeedf73 100644
> --- a/include/linux/pnfs_osd_xdr.h
> +++ b/include/linux/pnfs_osd_xdr.h
> @@ -154,6 +154,11 @@ enum pnfs_osd_targetid_type {
>  	OBJ_TARGET_SCSI_DEVICE_ID = 3,
>  };
>  
> +enum pnfs_osd_target_ota {
> +	OBJ_OTA_UNAVAILABLE = 0,
> +	OBJ_OTA_AVAILABLE = 1,
> +};
> +
>  /*   union pnfs_osd_targetid4 switch (pnfs_osd_targetid_type4 oti_type) {
>   *       case OBJ_TARGET_SCSI_NAME:
>   *           string              oti_scsi_name<>;


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin
  2012-03-16  6:23 ` [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin Boaz Harrosh
@ 2012-03-16 21:40   ` Myklebust, Trond
  2012-03-19 20:58     ` Boaz Harrosh
  2012-03-20  3:47   ` [PATCH version2] " Boaz Harrosh
  1 sibling, 1 reply; 17+ messages in thread
From: Myklebust, Trond @ 2012-03-16 21:40 UTC (permalink / raw)
  To: Boaz Harrosh
  Cc: NFS list, open-osd, Bhamare, Sachin, Benny Halevy, Steve Dickson,
	Welch, Brent

T24gVGh1LCAyMDEyLTAzLTE1IGF0IDIzOjIzIC0wNzAwLCBCb2F6IEhhcnJvc2ggd3JvdGU6DQo+
IEZyb206IFNhY2hpbiBCaGFtYXJlIDxzYmhhbWFyZUBwYW5hc2FzLmNvbT4NCj4gDQo+IFRoZSBw
bmZzLW9iamVjdHMgcHJvdG9jb2wgbWFuZGF0ZXMgdGhhdCB3ZSBhdXRvbG9naW4gaW50byBkZXZp
Y2VzIG5vdA0KPiBwcmVzZW50IGluIHRoZSBzeXN0ZW0sIGFjY29yZGluZyB0byBpbmZvcm1hdGlv
biBzcGVjaWZpZWQgaW4gdGhlDQo+IGdldF9kZXZpY2VfaW5mbyByZXR1cm5lZCBmcm9tIHRoZSBz
ZXJ2ZXIuDQo+IA0KPiBUaGUgUHJvdG9jb2wgc3BlY2lmaWVzIHR3byBsb2dpbiBoaW50cy4NCj4g
MS4gQW4gSVAgYWRkcmVzczpwb3J0IGNvbWJpbmF0aW9uDQo+IDIuIEEgc3RyaW5nIFVSSSB3aGlj
aCBpcyBjb25zdHJ1Y3RlZCBhcyBhIFVSTCB3aXRoIGEgcHJvdG9jb2wgcHJlZml4DQo+ICAgIGZv
bGxvd2VkIGJ5IDovLyBhbmQgYSBzdHJpbmcgYXMgYWRkcmVzcy4gRm9yIGVhY2ggIHByb3RvY29s
IHByZWZpeA0KPiAgICB0aGUgc3RyaW5nLWFkZHJlc3MgZm9ybWF0IG1pZ2h0IGJlIGRpZmZlcmVu
dC4NCj4gDQo+IFdlIG9ubHkgc3VwcG9ydCB0aGUgc2Vjb25kIG9wdGlvbi4gVGhlIGZpcnN0IG9w
dGlvbiBpcyBqdXN0IHJlZHVuZGFudA0KPiB0byB0aGUgc2Vjb25kIG9uZS4NCj4gTk9URTogVGhl
IEtlcm5lbCBwYXJ0IG9mIGF1dG9sb2dpbiBkb2VzIG5vdCBwYXJzZSB0aGUgVVJJIHN0cmluZy4g
SXQNCj4ganVzdCBjaGFubmVscyBpdCB0byBhIHVzZXItbW9kZSBzY3JpcHQuIFNvIGFueSBuZXcg
bG9naW4gcHJvdG9jb2xzIHNob3VsZA0KPiBvbmx5IHVwZGF0ZSB0aGUgdXNlci1tb2RlIHNjcmlw
dCB3aGljaCBpcyBhIHBhcnQgb2YgdGhlIG5mcy11dGlscyBwYWNrYWdlLA0KPiBidXQgdGhlIEtl
cm5lbCBuZWVkIG5vdCBjaGFuZ2UuDQo+IA0KPiBXZSBpbXBsZW1lbnQgdGhlIGF1dG9sb2dpbiBi
eSB1c2luZyB0aGUgY2FsbF91c2VybW9kZWhlbHBlcigpIEFQSS4NCj4gKFRoYW5rcyB0byBTdGV2
ZSBEaWNrc29uIDxzdGV2ZWRAcmVkaGF0LmNvbT4gZm9yIHBvaW50aW5nIGl0IG91dCkNCj4gU28g
dGhlcmUgaXMgbm8gcnVubmluZyBkYWVtb24gbmVlZGVkLCBhbmQgb3Igc3BlY2lhbCBzZXR1cC4N
Cj4gDQo+IEFsbCBpcyBuZWVkZWQgaXMgdGhhdCAiL3NiaW4vb3NkX2xvZ2luIiBzY3JpcHQgZXhp
c3RzLg0KPiBUT0RPOg0KPiAgICJvc2RfbG9naW4iIGlzIGFuIGhhcmQgY29kZWQgbmFtZS4gSWYg
bm90IHByZXNlbnQgd2Ugd2lsbCByYXRlX2xpbWl0DQo+ICAgcHJpbnQgdG8gZG1zZyBhbmQga2Vl
cCBmYWlsaW5nLiBJbiBzdWNoIGNhc2VzIHdlIHNob3VsZCBzdG9wIHRyeWluZw0KPiAgIGFuZCBw
cm92aWRlIHN5c2ZzIGludGVyZmFjZSBmb3IgcmUtZW5hYmxpbmcgYXV0b2xvZ2luLiBGb3IgZXhh
bXBsZSwNCj4gICB3ZSBjb3VsZCBaRVJPIG91dCB0aGUgc2NyaXB0IG5hbWUgYW5kIGxldCB1c2Vy
LW1vZGUgc2V0IGEgbmV3IHNjcmlwdA0KPiAgIG5hbWUuDQo+ICAgW1FdIFdoZXJlIGluIHN5c2Zz
IHNob3VsZCBhIGxheW91dC1kcml2ZXIgcHV0IGl0cyB0aGluZ3M/DQoNClBsZWFzZSBzZWUgZnMv
bmZzL2NhY2hlX2xpYi5jLCB3aGljaCBhbHJlYWR5IGRvZXMgdGhpcyBzb3J0IG9mIHRoaW5nLg0K
VGhlIHJpZ2h0IHRoaW5nIHRvIGRvIGlzIG5vdCBzeXNmcywgYnV0IGEga2VybmVsIG1vZHVsZSBw
YXJhbWV0ZXIuDQoNCg0KLS0gDQpUcm9uZCBNeWtsZWJ1c3QNCkxpbnV4IE5GUyBjbGllbnQgbWFp
bnRhaW5lcg0KDQpOZXRBcHANClRyb25kLk15a2xlYnVzdEBuZXRhcHAuY29tDQp3d3cubmV0YXBw
LmNvbQ0KDQo=

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin
  2012-03-16 21:40   ` Myklebust, Trond
@ 2012-03-19 20:58     ` Boaz Harrosh
  2012-03-19 21:12       ` Myklebust, Trond
  0 siblings, 1 reply; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-19 20:58 UTC (permalink / raw)
  To: Myklebust, Trond
  Cc: NFS list, open-osd, Bhamare, Sachin, Benny Halevy, Steve Dickson,
	Welch, Brent

On 03/16/2012 02:40 PM, Myklebust, Trond wrote:
> On Thu, 2012-03-15 at 23:23 -0700, Boaz Harrosh wrote:
>> From: Sachin Bhamare <sbhamare@panasas.com>
>>
>> The pnfs-objects protocol mandates that we autologin into devices not
>> present in the system, according to information specified in the
>> get_device_info returned from the server.
>>
>> The Protocol specifies two login hints.
>> 1. An IP address:port combination
>> 2. A string URI which is constructed as a URL with a protocol prefix
>>    followed by :// and a string as address. For each  protocol prefix
>>    the string-address format might be different.
>>
>> We only support the second option. The first option is just redundant
>> to the second one.
>> NOTE: The Kernel part of autologin does not parse the URI string. It
>> just channels it to a user-mode script. So any new login protocols should
>> only update the user-mode script which is a part of the nfs-utils package,
>> but the Kernel need not change.
>>
>> We implement the autologin by using the call_usermodehelper() API.
>> (Thanks to Steve Dickson <steved@redhat.com> for pointing it out)
>> So there is no running daemon needed, and or special setup.
>>
>> All is needed is that "/sbin/osd_login" script exists.
>> TODO:
>>   "osd_login" is an hard coded name. If not present we will rate_limit
>>   print to dmsg and keep failing. In such cases we should stop trying
>>   and provide sysfs interface for re-enabling autologin. For example,
>>   we could ZERO out the script name and let user-mode set a new script
>>   name.
>>   [Q] Where in sysfs should a layout-driver put its things?
> 
> Please see fs/nfs/cache_lib.c, which already does this sort of thing.
> The right thing to do is not sysfs, but a kernel module parameter.
> 

I have a question about the "kernel module parameter" is that an hot
affair. I mean if the module is loaded, does it have to be unloaded
before I can specify a new "module parameter" on load. Or it will
update globally even if the module is already loaded?

The reason I'm asking is because the layout-driver is referenced
by nfs-core on mount. And will not release until unmount, of the
last pnf-objects mount-point.

That's why I thought of a /sys so all mount-points need not be unmounted
before admin can fix the problem.

> 

Thanks
Boaz

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin
  2012-03-19 20:58     ` Boaz Harrosh
@ 2012-03-19 21:12       ` Myklebust, Trond
  2012-03-19 23:23         ` Boaz Harrosh
  0 siblings, 1 reply; 17+ messages in thread
From: Myklebust, Trond @ 2012-03-19 21:12 UTC (permalink / raw)
  To: Boaz Harrosh
  Cc: NFS list, open-osd, Bhamare, Sachin, Benny Halevy, Steve Dickson,
	Welch, Brent

T24gTW9uLCAyMDEyLTAzLTE5IGF0IDEzOjU4IC0wNzAwLCBCb2F6IEhhcnJvc2ggd3JvdGU6DQo+
IE9uIDAzLzE2LzIwMTIgMDI6NDAgUE0sIE15a2xlYnVzdCwgVHJvbmQgd3JvdGU6DQo+ID4gT24g
VGh1LCAyMDEyLTAzLTE1IGF0IDIzOjIzIC0wNzAwLCBCb2F6IEhhcnJvc2ggd3JvdGU6DQo+ID4+
IEZyb206IFNhY2hpbiBCaGFtYXJlIDxzYmhhbWFyZUBwYW5hc2FzLmNvbT4NCj4gPj4NCj4gPj4g
VGhlIHBuZnMtb2JqZWN0cyBwcm90b2NvbCBtYW5kYXRlcyB0aGF0IHdlIGF1dG9sb2dpbiBpbnRv
IGRldmljZXMgbm90DQo+ID4+IHByZXNlbnQgaW4gdGhlIHN5c3RlbSwgYWNjb3JkaW5nIHRvIGlu
Zm9ybWF0aW9uIHNwZWNpZmllZCBpbiB0aGUNCj4gPj4gZ2V0X2RldmljZV9pbmZvIHJldHVybmVk
IGZyb20gdGhlIHNlcnZlci4NCj4gPj4NCj4gPj4gVGhlIFByb3RvY29sIHNwZWNpZmllcyB0d28g
bG9naW4gaGludHMuDQo+ID4+IDEuIEFuIElQIGFkZHJlc3M6cG9ydCBjb21iaW5hdGlvbg0KPiA+
PiAyLiBBIHN0cmluZyBVUkkgd2hpY2ggaXMgY29uc3RydWN0ZWQgYXMgYSBVUkwgd2l0aCBhIHBy
b3RvY29sIHByZWZpeA0KPiA+PiAgICBmb2xsb3dlZCBieSA6Ly8gYW5kIGEgc3RyaW5nIGFzIGFk
ZHJlc3MuIEZvciBlYWNoICBwcm90b2NvbCBwcmVmaXgNCj4gPj4gICAgdGhlIHN0cmluZy1hZGRy
ZXNzIGZvcm1hdCBtaWdodCBiZSBkaWZmZXJlbnQuDQo+ID4+DQo+ID4+IFdlIG9ubHkgc3VwcG9y
dCB0aGUgc2Vjb25kIG9wdGlvbi4gVGhlIGZpcnN0IG9wdGlvbiBpcyBqdXN0IHJlZHVuZGFudA0K
PiA+PiB0byB0aGUgc2Vjb25kIG9uZS4NCj4gPj4gTk9URTogVGhlIEtlcm5lbCBwYXJ0IG9mIGF1
dG9sb2dpbiBkb2VzIG5vdCBwYXJzZSB0aGUgVVJJIHN0cmluZy4gSXQNCj4gPj4ganVzdCBjaGFu
bmVscyBpdCB0byBhIHVzZXItbW9kZSBzY3JpcHQuIFNvIGFueSBuZXcgbG9naW4gcHJvdG9jb2xz
IHNob3VsZA0KPiA+PiBvbmx5IHVwZGF0ZSB0aGUgdXNlci1tb2RlIHNjcmlwdCB3aGljaCBpcyBh
IHBhcnQgb2YgdGhlIG5mcy11dGlscyBwYWNrYWdlLA0KPiA+PiBidXQgdGhlIEtlcm5lbCBuZWVk
IG5vdCBjaGFuZ2UuDQo+ID4+DQo+ID4+IFdlIGltcGxlbWVudCB0aGUgYXV0b2xvZ2luIGJ5IHVz
aW5nIHRoZSBjYWxsX3VzZXJtb2RlaGVscGVyKCkgQVBJLg0KPiA+PiAoVGhhbmtzIHRvIFN0ZXZl
IERpY2tzb24gPHN0ZXZlZEByZWRoYXQuY29tPiBmb3IgcG9pbnRpbmcgaXQgb3V0KQ0KPiA+PiBT
byB0aGVyZSBpcyBubyBydW5uaW5nIGRhZW1vbiBuZWVkZWQsIGFuZCBvciBzcGVjaWFsIHNldHVw
Lg0KPiA+Pg0KPiA+PiBBbGwgaXMgbmVlZGVkIGlzIHRoYXQgIi9zYmluL29zZF9sb2dpbiIgc2Ny
aXB0IGV4aXN0cy4NCj4gPj4gVE9ETzoNCj4gPj4gICAib3NkX2xvZ2luIiBpcyBhbiBoYXJkIGNv
ZGVkIG5hbWUuIElmIG5vdCBwcmVzZW50IHdlIHdpbGwgcmF0ZV9saW1pdA0KPiA+PiAgIHByaW50
IHRvIGRtc2cgYW5kIGtlZXAgZmFpbGluZy4gSW4gc3VjaCBjYXNlcyB3ZSBzaG91bGQgc3RvcCB0
cnlpbmcNCj4gPj4gICBhbmQgcHJvdmlkZSBzeXNmcyBpbnRlcmZhY2UgZm9yIHJlLWVuYWJsaW5n
IGF1dG9sb2dpbi4gRm9yIGV4YW1wbGUsDQo+ID4+ICAgd2UgY291bGQgWkVSTyBvdXQgdGhlIHNj
cmlwdCBuYW1lIGFuZCBsZXQgdXNlci1tb2RlIHNldCBhIG5ldyBzY3JpcHQNCj4gPj4gICBuYW1l
Lg0KPiA+PiAgIFtRXSBXaGVyZSBpbiBzeXNmcyBzaG91bGQgYSBsYXlvdXQtZHJpdmVyIHB1dCBp
dHMgdGhpbmdzPw0KPiA+IA0KPiA+IFBsZWFzZSBzZWUgZnMvbmZzL2NhY2hlX2xpYi5jLCB3aGlj
aCBhbHJlYWR5IGRvZXMgdGhpcyBzb3J0IG9mIHRoaW5nLg0KPiA+IFRoZSByaWdodCB0aGluZyB0
byBkbyBpcyBub3Qgc3lzZnMsIGJ1dCBhIGtlcm5lbCBtb2R1bGUgcGFyYW1ldGVyLg0KPiA+IA0K
PiANCj4gSSBoYXZlIGEgcXVlc3Rpb24gYWJvdXQgdGhlICJrZXJuZWwgbW9kdWxlIHBhcmFtZXRl
ciIgaXMgdGhhdCBhbiBob3QNCj4gYWZmYWlyLiBJIG1lYW4gaWYgdGhlIG1vZHVsZSBpcyBsb2Fk
ZWQsIGRvZXMgaXQgaGF2ZSB0byBiZSB1bmxvYWRlZA0KPiBiZWZvcmUgSSBjYW4gc3BlY2lmeSBh
IG5ldyAibW9kdWxlIHBhcmFtZXRlciIgb24gbG9hZC4gT3IgaXQgd2lsbA0KPiB1cGRhdGUgZ2xv
YmFsbHkgZXZlbiBpZiB0aGUgbW9kdWxlIGlzIGFscmVhZHkgbG9hZGVkPw0KPiANCj4gVGhlIHJl
YXNvbiBJJ20gYXNraW5nIGlzIGJlY2F1c2UgdGhlIGxheW91dC1kcml2ZXIgaXMgcmVmZXJlbmNl
ZA0KPiBieSBuZnMtY29yZSBvbiBtb3VudC4gQW5kIHdpbGwgbm90IHJlbGVhc2UgdW50aWwgdW5t
b3VudCwgb2YgdGhlDQo+IGxhc3QgcG5mLW9iamVjdHMgbW91bnQtcG9pbnQuDQo+IA0KPiBUaGF0
J3Mgd2h5IEkgdGhvdWdodCBvZiBhIC9zeXMgc28gYWxsIG1vdW50LXBvaW50cyBuZWVkIG5vdCBi
ZSB1bm1vdW50ZWQNCj4gYmVmb3JlIGFkbWluIGNhbiBmaXggdGhlIHByb2JsZW0uDQoNClllcy4g
SWYgeW91IGRlc2lnbiB0aGluZ3MgY29ycmVjdGx5LCB5b3UgY2FuIG1ha2UgdGhlIGtlcm5lbCBw
YXJhbWV0ZXINCndyaXRlYWJsZSBieSBzZXR0aW5nIHRoZSBtb2RlIGluIHRoZSBtb2R1bGVfcGFy
YW1fc3RyaW5nKCkuIEFnYWluLA0KcGxlYXNlIHNlZSBmcy9uZnMvY2FjaGVfbGliLmMuDQoNClRo
ZSBhZHZhbnRhZ2Ugb2YgdGhlIGtlcm5lbCBwYXJhbWV0ZXIgaGVyZSBpcyB0aGF0IHlvdSBjYW4g
aW5pdGlhbGlzZSBpdA0KZGlyZWN0bHkgaW4gL2V0Yy9tb2Rwcm9iZS5jb25mIHVzaW5nIHRoZSAn
b3B0aW9ucycgY29tbWFuZCwgYnV0IHlvdSBjYW4NCmxhdGVyIGNoYW5nZSBpdCBkeW5hbWljYWxs
eSAod2l0aG91dCByZW1vdmluZyB0aGUgbW9kdWxlKSB1c2luZyB0aGUNCnBzZXVkb2ZpbGUgaW4g
L3N5cy9tb2R1bGUvb2JqbGF5b3V0LWRyaXZlci9wYXJhbWV0ZXJzDQoNCi0tIA0KVHJvbmQgTXlr
bGVidXN0DQpMaW51eCBORlMgY2xpZW50IG1haW50YWluZXINCg0KTmV0QXBwDQpUcm9uZC5NeWts
ZWJ1c3RAbmV0YXBwLmNvbQ0Kd3d3Lm5ldGFwcC5jb20NCg0K

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin
  2012-03-19 21:12       ` Myklebust, Trond
@ 2012-03-19 23:23         ` Boaz Harrosh
  2012-03-20  1:16           ` Boaz Harrosh
  0 siblings, 1 reply; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-19 23:23 UTC (permalink / raw)
  To: Myklebust, Trond
  Cc: NFS list, open-osd, Bhamare, Sachin, Benny Halevy, Steve Dickson,
	Welch, Brent

On 03/19/2012 02:12 PM, Myklebust, Trond wrote:
> On Mon, 2012-03-19 at 13:58 -0700, Boaz Harrosh wrote:
>> On 03/16/2012 02:40 PM, Myklebust, Trond wrote:
>>> On Thu, 2012-03-15 at 23:23 -0700, Boaz Harrosh wrote:
>>>> From: Sachin Bhamare <sbhamare@panasas.com>
>>>>
>>>> The pnfs-objects protocol mandates that we autologin into devices not
>>>> present in the system, according to information specified in the
>>>> get_device_info returned from the server.
>>>>
>>>> The Protocol specifies two login hints.
>>>> 1. An IP address:port combination
>>>> 2. A string URI which is constructed as a URL with a protocol prefix
>>>>    followed by :// and a string as address. For each  protocol prefix
>>>>    the string-address format might be different.
>>>>
>>>> We only support the second option. The first option is just redundant
>>>> to the second one.
>>>> NOTE: The Kernel part of autologin does not parse the URI string. It
>>>> just channels it to a user-mode script. So any new login protocols should
>>>> only update the user-mode script which is a part of the nfs-utils package,
>>>> but the Kernel need not change.
>>>>
>>>> We implement the autologin by using the call_usermodehelper() API.
>>>> (Thanks to Steve Dickson <steved@redhat.com> for pointing it out)
>>>> So there is no running daemon needed, and or special setup.
>>>>
>>>> All is needed is that "/sbin/osd_login" script exists.
>>>> TODO:
>>>>   "osd_login" is an hard coded name. If not present we will rate_limit
>>>>   print to dmsg and keep failing. In such cases we should stop trying
>>>>   and provide sysfs interface for re-enabling autologin. For example,
>>>>   we could ZERO out the script name and let user-mode set a new script
>>>>   name.
>>>>   [Q] Where in sysfs should a layout-driver put its things?
>>>
>>> Please see fs/nfs/cache_lib.c, which already does this sort of thing.
>>> The right thing to do is not sysfs, but a kernel module parameter.
>>>
>>
>> I have a question about the "kernel module parameter" is that an hot
>> affair. I mean if the module is loaded, does it have to be unloaded
>> before I can specify a new "module parameter" on load. Or it will
>> update globally even if the module is already loaded?
>>
>> The reason I'm asking is because the layout-driver is referenced
>> by nfs-core on mount. And will not release until unmount, of the
>> last pnf-objects mount-point.
>>
>> That's why I thought of a /sys so all mount-points need not be unmounted
>> before admin can fix the problem.
> 
> Yes. If you design things correctly, you can make the kernel parameter
> writeable by setting the mode in the module_param_string(). Again,
> please see fs/nfs/cache_lib.c.
> 
> The advantage of the kernel parameter here is that you can initialise it
> directly in /etc/modprobe.conf using the 'options' command, but you can
> later change it dynamically (without removing the module) using the
> pseudofile in /sys/module/objlayout-driver/parameters
> 

Perfect thanks. Done. I'll send the patch soon. Am now testing it.
I want to test all the possible options and the dynamic change.

Thanks
Boaz
 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin
  2012-03-19 23:23         ` Boaz Harrosh
@ 2012-03-20  1:16           ` Boaz Harrosh
  2012-03-20  3:10             ` Boaz Harrosh
  0 siblings, 1 reply; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-20  1:16 UTC (permalink / raw)
  To: Myklebust, Trond, Bhamare, Sachin
  Cc: NFS list, open-osd, Benny Halevy, Steve Dickson, Welch, Brent

Sachin hi

I'm sending in the SQUASHME to this patch which changes the code
according to Trond's comments. (See comments below)

Trond don't submit as is, wait for the [version 2] patch that should be
submitted instead of the previous one. I'm only sending this one for
comments.

I'm in the middle of heavy testing, once done I'll send the revised
patch

Thanks
Boaz

---
From: Boaz Harrosh <bharrosh@panasas.com>
Date: Mon, 19 Mar 2012 17:59:08 -0700
Subject: [PATCH] SQUASHME: pnf-obj: Fix as according to Trond's comments

* Add the osd_login_prog and osd_login_upcall_timeout module parameters
* Disable any farther upcalls in case the osd_login user-mode program was not
   found. Until Admin re-enables it by setting the osd_login_prog parameter.
* Don't wait for ever for osd_login to finish, only wait osd_login_upcall_timeout
    number of seconds, else fail.
* HOME environment should be "/" not "/root" because "/" will always exist
* Add text to Documentation/filesystems/nfs/pnfs.txt about the API to
   osd_login
* Add Documentation of the new  osd_login_prog and osd_login_upcall_timeout
   to Documentation/kernel-parameters.txt

Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
 Documentation/filesystems/nfs/pnfs.txt |   54 ++++++++++++++++++++++
 Documentation/kernel-parameters.txt    |   12 +++++
 fs/nfs/objlayout/objlayout.c           |   77 +++++++++++++++++++++++++++----
 3 files changed, 133 insertions(+), 10 deletions(-)

diff --git a/Documentation/filesystems/nfs/pnfs.txt b/Documentation/filesystems/nfs/pnfs.txt
index 983e14a..cc08e53 100644
--- a/Documentation/filesystems/nfs/pnfs.txt
+++ b/Documentation/filesystems/nfs/pnfs.txt
@@ -53,3 +53,57 @@ lseg maintains an extra reference corresponding to the NFS_LSEG_VALID
 bit which holds it in the pnfs_layout_hdr's list.  When the final lseg
 is removed from the pnfs_layout_hdr's list, the NFS_LAYOUT_DESTROYED
 bit is set, preventing any new lsegs from being added.
+
+layout drivers
+--------------
+
+PNFS utilizes what is called layout drivers. The STD defines 3 basic
+layout types: "files" "objects" and "blocks". For each of these types
+there is a layout-driver with a common function-vectors table which
+are called by the nfs-client pnfs-core to implement the different layout
+types.
+
+Files-layout-driver code is in: fs/nfs/nfs4filelayout.c && nfs4filelayoutdev.c
+Objects-layout-deriver code is in: fs/nfs/objlayout/.. directory
+Blocks-layout-deriver code is in: fs/nfs/blocklayout/.. directory
+
+objects-layout setup
+--------------------
+
+As part of the full STD implementation the objlayoutdriver.ko needs, at times,
+to automatically login to yet undiscovered iscsi/osd devices. For this the
+driver makes up-calles to a user-mode script called *osd_login*
+
+The path_name of the script to use is by default:
+	/sbin/osd_login.
+This name can be overridden by the Kernel module parameter:
+	objlayoutdriver.osd_login_prog
+The command, if fails to return in a timely manner will fail. The:
+	objlayoutdriver.osd_login_upcall_timeout
+Governs the time to wait, it defaults to 15 seconds.
+
+If Kernel does not find the osd_login_prog path it will zero it out
+and will not attempt farther logins. An admin can then write new value
+to the objlayoutdriver.osd_login_prog Kernel parameter to re-enable it.
+
+The API to the login script is as follows:
+	Usage: $0 -u <URI> -o <OSDNAME> -s <SYSTEMID>
+	Options:
+		-u		target uri e.g. iscsi://<ip>:<port>
+				(allways exists)
+				(More protocols can be defined in the future.
+				 The client does not interpret this string it is
+				 passed unchanged as recieved from the Server)
+		-o		osdname of the requested target OSD
+				(Might be empty)
+				(A string which denotes the OSD name, there is a
+				 limit of 64 chars on this string)
+		-s 		systemid of the requested target OSD
+				(Might be empty)
+				(This string, if not empty is always an hex
+				 representation of the 20 bytes osd_system_id)
+
+blocks-layout setup
+-------------------
+
+TODO: Document the setup needs of the blocks layout driver
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 033d4e6..4b298cf 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1670,6 +1670,18 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			back to using the idmapper.
 			To turn off this behaviour, set the value to '0'.
 
+	objlayoutdriver.osd_login_prog=
+			[NFS] [OBJLAYOUT] sets the pathname to the program which
+			is used to automatically discover and login into new
+			osd-targets. Please see:
+			Documentation/filesystems/pnfs.txt for more explanations
+
+	objlayoutdriver.osd_login_upcall_timeout=
+			[NFS] [OBJLAYOUT] sets the timeout after which an
+			attempt to auto-osd-login is deemed to have failed.
+			Please see:
+			Documentation/filesystems/pnfs.txt for more explanations
+
 	nmi_debug=	[KNL,AVR32,SH] Specify one or more actions to take
 			when a NMI is triggered.
 			Format: [state][,regs][,debounce][,die]
diff --git a/fs/nfs/objlayout/objlayout.c b/fs/nfs/objlayout/objlayout.c
index d953948..5789206 100644
--- a/fs/nfs/objlayout/objlayout.c
+++ b/fs/nfs/objlayout/objlayout.c
@@ -38,6 +38,7 @@
  */
 
 #include <linux/kmod.h>
+#include <linux/moduleparam.h>
 #include <linux/ratelimit.h>
 #include <scsi/osd_initiator.h>
 #include "objlayout.h"
@@ -652,33 +653,79 @@ void objlayout_put_deviceinfo(struct pnfs_osd_deviceaddr *deviceaddr)
 	kfree(odi);
 }
 
-static const char osd_login_prog[] = "/sbin/osd_login";
-
 enum {
 	OBJLAYOUT_MAX_URI_LEN = 256, OBJLAYOUT_MAX_OSDNAME_LEN = 64,
 	OBJLAYOUT_MAX_SYSID_HEX_LEN = OSD_SYSTEMID_LEN * 2 + 1,
+	OSD_LOGIN_UPCALL_PATHLEN  = 256, OSD_LOGIN_UPCALL_TIMEOUT = 15,
 };
 
+static char osd_login_prog[OSD_LOGIN_UPCALL_PATHLEN] = "/sbin/osd_login";
+
+static unsigned long osd_login_upcall_timeout = OSD_LOGIN_UPCALL_TIMEOUT;
+
+module_param_string(osd_login_prog, osd_login_prog, sizeof(osd_login_prog),
+		    0600);
+MODULE_PARM_DESC(osd_login_prog, "Path to the osd_login upcall program");
+module_param_named(osd_login_upcall_timeout, osd_login_upcall_timeout, ulong,
+		   0600);
+MODULE_PARM_DESC(osd_login_upcall_timeout, "Timeout (in seconds) after which "
+		"the osd_login is assumed to have failed");
+
 struct __auto_login {
 	char uri[OBJLAYOUT_MAX_URI_LEN];
 	char osdname[OBJLAYOUT_MAX_OSDNAME_LEN];
 	char systemid_hex[OBJLAYOUT_MAX_SYSID_HEX_LEN];
 };
 
+struct __upcall_wait {
+	struct kref kref;
+	struct completion wait;
+};
+
+static void __upcall_wait_release(struct kref *kref)
+{
+	struct __upcall_wait *uw = container_of(kref, struct __upcall_wait,
+						kref);
+
+	kfree(uw);
+}
+
+static void __upcall_cleanup(struct subprocess_info *si)
+{
+	struct __upcall_wait *uw = si->data;
+
+	complete(&uw->wait);
+	kref_put(&uw->kref, __upcall_wait_release);
+}
+
 static int __objlayout_upcall(struct __auto_login *login)
 {
-	static char *envp[] = { "HOME=/root",
+	static char *envp[] = { "HOME=/",
 		"TERM=linux",
 		"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
 		NULL
 	};
 	char *argv[8];
+	struct __upcall_wait *uw;
 	int ret;
 
 	dprintk("%s uri: %s\n", __func__, login->uri);
 	dprintk("%s osdname %s\n", __func__, login->osdname);
 	dprintk("%s systemid_hex %s\n", __func__, login->systemid_hex);
 
+	if (unlikely(!osd_login_prog[0])) {
+		dprintk("%s: osd_login_prog is disabled\n", __func__);
+		return -EACCES;
+	}
+
+	uw = kzalloc(sizeof(*uw), GFP_KERNEL);
+	if (unlikely(!uw)) {
+		dprintk("%s: allocation of __upcall_wait failed\n", __func__);
+		return -ENOMEM;
+	}
+	kref_init(&uw->kref);
+	init_completion(&uw->wait);
+
 	argv[0] = (char *)osd_login_prog;
 	argv[1] = "-u";
 	argv[2] = login->uri;
@@ -688,16 +735,26 @@ static int __objlayout_upcall(struct __auto_login *login)
 	argv[6] = login->systemid_hex;
 	argv[7] = NULL;
 
-	ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
+	ret = call_usermodehelper_fns(argv[0], argv, envp, UMH_WAIT_EXEC, NULL,
+				      __upcall_cleanup, uw);
 	/*
-	 * TODO: Disable the upcall mechanism if we're getting an ENOENT or
+	 * Disable the upcall mechanism if we're getting an ENOENT or
 	 * EACCES error. The admin can re-enable it on the fly by using
-	 * sysfs to set the parameter once the problem has been fixed.
+	 * sysfs to set the objlayoutdriver.osd_login_prog module parameter once
+	 * the problem has been fixed.
 	 */
-	if (ret == -ENOENT || ret == -EACCES)
-		pr_warn_ratelimited("PNFS-OBJ:: %s: %s "
-			"was not found please install new nfs-utils pkg!\n",
-			__func__, osd_login_prog);
+	if (ret == -ENOENT || ret == -EACCES) {
+		printk(KERN_ERR "PNFS-OBJ: %s was not found please set "
+			"objlayoutdriver.osd_login_prog kernel parameter!\n",
+			osd_login_prog);
+		osd_login_prog[0] = '\0';
+		goto out;
+	}
+	ret = wait_for_completion_timeout(&uw->wait,
+					  osd_login_upcall_timeout * HZ) ?
+						0 : -ETIMEDOUT;
+out:
+	kref_put(&uw->kref, __upcall_wait_release);
 	dprintk("%s %s return value: %d\n", __func__, osd_login_prog, ret);
 
 	return ret;
-- 
1.7.6.5



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin
  2012-03-20  1:16           ` Boaz Harrosh
@ 2012-03-20  3:10             ` Boaz Harrosh
  2012-03-20  3:26               ` Boaz Harrosh
  0 siblings, 1 reply; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-20  3:10 UTC (permalink / raw)
  To: Myklebust, Trond, Bhamare, Sachin
  Cc: NFS list, open-osd, Benny Halevy, Steve Dickson, Welch, Brent

On 03/19/2012 06:16 PM, Boaz Harrosh wrote:
> Subject: [PATCH] SQUASHME: pnf-obj: Fix as according to Trond's comments
> 

<snip>

> * Don't wait for ever for osd_login to finish, only wait osd_login_upcall_timeout
>     number of seconds, else fail.


OK I'm dropping this thing for now. The call to call_usermodehelper_xxx infrastructure
is not built for this.

What happens is that the (*cleanup) function passed to call_usermodehelper_fns is always
call from within the call_usermodehelper_fns(), before it's return. If it's waiting
for the execution - UMH_WAIT_EXEC - then just after execution, if UMH_WAIT_PROC then
after the program ends, if UMH_NO_WAIT it is called immediately. So there is no event
out of the kmode.c subsystem that can always notify us when the PROC ended.

For that I will need to either spun yet another thread, (The call_usermodehelper_exec
already spuns 3. Or change call_usermodehelper_exec to receive a third vector that
will be called on PROC completion. (Which will be redundant if  UMH_WAIT_PROC)

Since both options are too heavyweights for me right now, I will leave this option
to a TODO, and drop the timeout support for now.

Trond please confirm.

Thanks
Boaz

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin
  2012-03-20  3:10             ` Boaz Harrosh
@ 2012-03-20  3:26               ` Boaz Harrosh
  0 siblings, 0 replies; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-20  3:26 UTC (permalink / raw)
  To: Myklebust, Trond, Bhamare, Sachin
  Cc: NFS list, open-osd, Benny Halevy, Steve Dickson, Welch, Brent

This is the final SQUASHME that will be applied to the original
	pnfs-obj: autologin: Add support for protocol autologin

With this one I'm passing tests and am able to disable enable
re-enable auto login from user-mode.

I've tested all the combinations of /sbin/osd_login not present
and re-enable by setting
	/sys/module/objlayoutdriver/parameters/osd_login_prog


[The diff from the last one is that the timeout thing was removed
 from code and documentation]

Thanks Trond for your comments
Boaz

---
From: Boaz Harrosh <bharrosh@panasas.com>
Subject: [PATCH VER2] SQUASHME: pnf-obj: Fix as according to Trond's comments

* Add the osd_login_prog Kernel module parameters
* Disable any farther upcalls in case the osd_login user-mode program was not
   found. Until Admin re-enables it by setting the osd_login_prog parameter.
* HOME environment should be "/" not "/root" because "/" will always exist
* Add text about the osd_login program command line API to:
	Documentation/filesystems/nfs/pnfs.txt
* Add Documentation of the new  osd_login_prog  module parameter to:
	Documentation/kernel-parameters.txt

TODO: Add timeout option in the case osd_login program gets
              stuck

Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
 Documentation/filesystems/nfs/pnfs.txt |   54 ++++++++++++++++++++++++++++++++
 Documentation/kernel-parameters.txt    |    6 +++
 fs/nfs/objlayout/objlayout.c           |   32 +++++++++++++-----
 3 files changed, 83 insertions(+), 9 deletions(-)

diff --git a/Documentation/filesystems/nfs/pnfs.txt b/Documentation/filesystems/nfs/pnfs.txt
index 983e14a..c7919c6 100644
--- a/Documentation/filesystems/nfs/pnfs.txt
+++ b/Documentation/filesystems/nfs/pnfs.txt
@@ -53,3 +53,57 @@ lseg maintains an extra reference corresponding to the NFS_LSEG_VALID
 bit which holds it in the pnfs_layout_hdr's list.  When the final lseg
 is removed from the pnfs_layout_hdr's list, the NFS_LAYOUT_DESTROYED
 bit is set, preventing any new lsegs from being added.
+
+layout drivers
+--------------
+
+PNFS utilizes what is called layout drivers. The STD defines 3 basic
+layout types: "files" "objects" and "blocks". For each of these types
+there is a layout-driver with a common function-vectors table which
+are called by the nfs-client pnfs-core to implement the different layout
+types.
+
+Files-layout-driver code is in: fs/nfs/nfs4filelayout.c && nfs4filelayoutdev.c
+Objects-layout-deriver code is in: fs/nfs/objlayout/.. directory
+Blocks-layout-deriver code is in: fs/nfs/blocklayout/.. directory
+
+objects-layout setup
+--------------------
+
+As part of the full STD implementation the objlayoutdriver.ko needs, at times,
+to automatically login to yet undiscovered iscsi/osd devices. For this the
+driver makes up-calles to a user-mode script called *osd_login*
+
+The path_name of the script to use is by default:
+	/sbin/osd_login.
+This name can be overridden by the Kernel module parameter:
+	objlayoutdriver.osd_login_prog
+
+If Kernel does not find the osd_login_prog path it will zero it out
+and will not attempt farther logins. An admin can then write new value
+to the objlayoutdriver.osd_login_prog Kernel parameter to re-enable it.
+
+The /sbin/osd_login is part of the nfs-utils package, and should usually
+be installed on distributions that support this Kernel version.
+
+The API to the login script is as follows:
+	Usage: $0 -u <URI> -o <OSDNAME> -s <SYSTEMID>
+	Options:
+		-u		target uri e.g. iscsi://<ip>:<port>
+				(allways exists)
+				(More protocols can be defined in the future.
+				 The client does not interpret this string it is
+				 passed unchanged as recieved from the Server)
+		-o		osdname of the requested target OSD
+				(Might be empty)
+				(A string which denotes the OSD name, there is a
+				 limit of 64 chars on this string)
+		-s 		systemid of the requested target OSD
+				(Might be empty)
+				(This string, if not empty is always an hex
+				 representation of the 20 bytes osd_system_id)
+
+blocks-layout setup
+-------------------
+
+TODO: Document the setup needs of the blocks layout driver
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 033d4e6..d5a2f09 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1670,6 +1670,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			back to using the idmapper.
 			To turn off this behaviour, set the value to '0'.
 
+	objlayoutdriver.osd_login_prog=
+			[NFS] [OBJLAYOUT] sets the pathname to the program which
+			is used to automatically discover and login into new
+			osd-targets. Please see:
+			Documentation/filesystems/pnfs.txt for more explanations
+
 	nmi_debug=	[KNL,AVR32,SH] Specify one or more actions to take
 			when a NMI is triggered.
 			Format: [state][,regs][,debounce][,die]
diff --git a/fs/nfs/objlayout/objlayout.c b/fs/nfs/objlayout/objlayout.c
index d953948..b158d1b 100644
--- a/fs/nfs/objlayout/objlayout.c
+++ b/fs/nfs/objlayout/objlayout.c
@@ -38,6 +38,7 @@
  */
 
 #include <linux/kmod.h>
+#include <linux/moduleparam.h>
 #include <linux/ratelimit.h>
 #include <scsi/osd_initiator.h>
 #include "objlayout.h"
@@ -652,13 +653,18 @@ void objlayout_put_deviceinfo(struct pnfs_osd_deviceaddr *deviceaddr)
 	kfree(odi);
 }
 
-static const char osd_login_prog[] = "/sbin/osd_login";
-
 enum {
 	OBJLAYOUT_MAX_URI_LEN = 256, OBJLAYOUT_MAX_OSDNAME_LEN = 64,
 	OBJLAYOUT_MAX_SYSID_HEX_LEN = OSD_SYSTEMID_LEN * 2 + 1,
+	OSD_LOGIN_UPCALL_PATHLEN  = 256
 };
 
+static char osd_login_prog[OSD_LOGIN_UPCALL_PATHLEN] = "/sbin/osd_login";
+
+module_param_string(osd_login_prog, osd_login_prog, sizeof(osd_login_prog),
+		    0600);
+MODULE_PARM_DESC(osd_login_prog, "Path to the osd_login upcall program");
+
 struct __auto_login {
 	char uri[OBJLAYOUT_MAX_URI_LEN];
 	char osdname[OBJLAYOUT_MAX_OSDNAME_LEN];
@@ -667,7 +673,7 @@ struct __auto_login {
 
 static int __objlayout_upcall(struct __auto_login *login)
 {
-	static char *envp[] = { "HOME=/root",
+	static char *envp[] = { "HOME=/",
 		"TERM=linux",
 		"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
 		NULL
@@ -675,6 +681,11 @@ static int __objlayout_upcall(struct __auto_login *login)
 	char *argv[8];
 	int ret;
 
+	if (unlikely(!osd_login_prog[0])) {
+		dprintk("%s: osd_login_prog is disabled\n", __func__);
+		return -EACCES;
+	}
+
 	dprintk("%s uri: %s\n", __func__, login->uri);
 	dprintk("%s osdname %s\n", __func__, login->osdname);
 	dprintk("%s systemid_hex %s\n", __func__, login->systemid_hex);
@@ -690,14 +701,17 @@ static int __objlayout_upcall(struct __auto_login *login)
 
 	ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
 	/*
-	 * TODO: Disable the upcall mechanism if we're getting an ENOENT or
+	 * Disable the upcall mechanism if we're getting an ENOENT or
 	 * EACCES error. The admin can re-enable it on the fly by using
-	 * sysfs to set the parameter once the problem has been fixed.
+	 * sysfs to set the objlayoutdriver.osd_login_prog module parameter once
+	 * the problem has been fixed.
 	 */
-	if (ret == -ENOENT || ret == -EACCES)
-		pr_warn_ratelimited("PNFS-OBJ:: %s: %s "
-			"was not found please install new nfs-utils pkg!\n",
-			__func__, osd_login_prog);
+	if (ret == -ENOENT || ret == -EACCES) {
+		printk(KERN_ERR "PNFS-OBJ: %s was not found please set "
+			"objlayoutdriver.osd_login_prog kernel parameter!\n",
+			osd_login_prog);
+		osd_login_prog[0] = '\0';
+	}
 	dprintk("%s %s return value: %d\n", __func__, osd_login_prog, ret);
 
 	return ret;
-- 
1.7.6.5


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH version2] pnfs-obj: autologin: Add support for protocol autologin
  2012-03-16  6:23 ` [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin Boaz Harrosh
  2012-03-16 21:40   ` Myklebust, Trond
@ 2012-03-20  3:47   ` Boaz Harrosh
  1 sibling, 0 replies; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-20  3:47 UTC (permalink / raw)
  To: Boaz Harrosh, Trond Myklebust, NFS list, open-osd, Bhamare, Sachin
  Cc: Benny Halevy, Steve Dickson, Welch, Brent

From: Sachin Bhamare <sbhamare@panasas.com>

The pnfs-objects protocol mandates that we autologin into devices not
present in the system, according to information specified in the
get_device_info returned from the server.

The Protocol specifies two login hints.
1. An IP address:port combination
2. A string URI which is constructed as a URL with a protocol prefix
   followed by :// and a string as address. For each  protocol prefix
   the string-address format might be different.

We only support the second option. The first option is just redundant
to the second one.
NOTE: The Kernel part of autologin does not parse the URI string. It
just channels it to a user-mode script. So any new login protocols should
only update the user-mode script which is a part of the nfs-utils package,
but the Kernel need not change.

We implement the autologin by using the call_usermodehelper() API.
(Thanks to Steve Dickson <steved@redhat.com> for pointing it out)
So there is no running daemon needed, and/or special setup.

We Add the osd_login_prog Kernel module parameters which defaults to:
	/sbin/osd_login

Kernel try's to upcall the program specified in osd_login_prog. If the file is
not found or the execution fails Kernel will disable any farther upcalls, by
zeroing out  osd_login_prog, Until Admin re-enables it by setting the
osd_login_prog parameter to a proper program.

Also add text about the osd_login program command line API to:
	Documentation/filesystems/nfs/pnfs.txt
and documentation of the new  osd_login_prog  module parameter to:
	Documentation/kernel-parameters.txt

TODO: Add timeout option in the case osd_login program gets
              stuck

Signed-off-by: Sachin Bhamare <sbhamare@panasas.com>
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
 Documentation/filesystems/nfs/pnfs.txt |   54 +++++++++++++
 Documentation/kernel-parameters.txt    |    6 ++
 fs/nfs/objlayout/objio_osd.c           |    9 ++
 fs/nfs/objlayout/objlayout.c           |  134 ++++++++++++++++++++++++++++++++
 fs/nfs/objlayout/objlayout.h           |    2 +
 5 files changed, 205 insertions(+), 0 deletions(-)

diff --git a/Documentation/filesystems/nfs/pnfs.txt b/Documentation/filesystems/nfs/pnfs.txt
index 983e14a..c7919c6 100644
--- a/Documentation/filesystems/nfs/pnfs.txt
+++ b/Documentation/filesystems/nfs/pnfs.txt
@@ -53,3 +53,57 @@ lseg maintains an extra reference corresponding to the NFS_LSEG_VALID
 bit which holds it in the pnfs_layout_hdr's list.  When the final lseg
 is removed from the pnfs_layout_hdr's list, the NFS_LAYOUT_DESTROYED
 bit is set, preventing any new lsegs from being added.
+
+layout drivers
+--------------
+
+PNFS utilizes what is called layout drivers. The STD defines 3 basic
+layout types: "files" "objects" and "blocks". For each of these types
+there is a layout-driver with a common function-vectors table which
+are called by the nfs-client pnfs-core to implement the different layout
+types.
+
+Files-layout-driver code is in: fs/nfs/nfs4filelayout.c && nfs4filelayoutdev.c
+Objects-layout-deriver code is in: fs/nfs/objlayout/.. directory
+Blocks-layout-deriver code is in: fs/nfs/blocklayout/.. directory
+
+objects-layout setup
+--------------------
+
+As part of the full STD implementation the objlayoutdriver.ko needs, at times,
+to automatically login to yet undiscovered iscsi/osd devices. For this the
+driver makes up-calles to a user-mode script called *osd_login*
+
+The path_name of the script to use is by default:
+	/sbin/osd_login.
+This name can be overridden by the Kernel module parameter:
+	objlayoutdriver.osd_login_prog
+
+If Kernel does not find the osd_login_prog path it will zero it out
+and will not attempt farther logins. An admin can then write new value
+to the objlayoutdriver.osd_login_prog Kernel parameter to re-enable it.
+
+The /sbin/osd_login is part of the nfs-utils package, and should usually
+be installed on distributions that support this Kernel version.
+
+The API to the login script is as follows:
+	Usage: $0 -u <URI> -o <OSDNAME> -s <SYSTEMID>
+	Options:
+		-u		target uri e.g. iscsi://<ip>:<port>
+				(allways exists)
+				(More protocols can be defined in the future.
+				 The client does not interpret this string it is
+				 passed unchanged as recieved from the Server)
+		-o		osdname of the requested target OSD
+				(Might be empty)
+				(A string which denotes the OSD name, there is a
+				 limit of 64 chars on this string)
+		-s 		systemid of the requested target OSD
+				(Might be empty)
+				(This string, if not empty is always an hex
+				 representation of the 20 bytes osd_system_id)
+
+blocks-layout setup
+-------------------
+
+TODO: Document the setup needs of the blocks layout driver
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 033d4e6..d5a2f09 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1670,6 +1670,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			back to using the idmapper.
 			To turn off this behaviour, set the value to '0'.
 
+	objlayoutdriver.osd_login_prog=
+			[NFS] [OBJLAYOUT] sets the pathname to the program which
+			is used to automatically discover and login into new
+			osd-targets. Please see:
+			Documentation/filesystems/pnfs.txt for more explanations
+
 	nmi_debug=	[KNL,AVR32,SH] Specify one or more actions to take
 			when a NMI is triggered.
 			Format: [state][,regs][,debounce][,die]
diff --git a/fs/nfs/objlayout/objio_osd.c b/fs/nfs/objlayout/objio_osd.c
index 37a9269..5b2ac9e 100644
--- a/fs/nfs/objlayout/objio_osd.c
+++ b/fs/nfs/objlayout/objio_osd.c
@@ -137,6 +137,7 @@ static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
 	struct objio_dev_ent *ode;
 	struct osd_dev *od;
 	struct osd_dev_info odi;
+	bool retry_flag = true;
 	int err;
 
 	ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id);
@@ -171,10 +172,18 @@ static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
 		goto out;
 	}
 
+retry_lookup:
 	od = osduld_info_lookup(&odi);
 	if (unlikely(IS_ERR(od))) {
 		err = PTR_ERR(od);
 		dprintk("%s: osduld_info_lookup => %d\n", __func__, err);
+		if (err == -ENODEV && retry_flag) {
+			err = objlayout_autologin(deviceaddr);
+			if (likely(!err)) {
+				retry_flag = false;
+				goto retry_lookup;
+			}
+		}
 		goto out;
 	}
 
diff --git a/fs/nfs/objlayout/objlayout.c b/fs/nfs/objlayout/objlayout.c
index 71047c9..b158d1b 100644
--- a/fs/nfs/objlayout/objlayout.c
+++ b/fs/nfs/objlayout/objlayout.c
@@ -37,6 +37,9 @@
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <linux/kmod.h>
+#include <linux/moduleparam.h>
+#include <linux/ratelimit.h>
 #include <scsi/osd_initiator.h>
 #include "objlayout.h"
 
@@ -649,3 +652,134 @@ void objlayout_put_deviceinfo(struct pnfs_osd_deviceaddr *deviceaddr)
 	__free_page(odi->page);
 	kfree(odi);
 }
+
+enum {
+	OBJLAYOUT_MAX_URI_LEN = 256, OBJLAYOUT_MAX_OSDNAME_LEN = 64,
+	OBJLAYOUT_MAX_SYSID_HEX_LEN = OSD_SYSTEMID_LEN * 2 + 1,
+	OSD_LOGIN_UPCALL_PATHLEN  = 256
+};
+
+static char osd_login_prog[OSD_LOGIN_UPCALL_PATHLEN] = "/sbin/osd_login";
+
+module_param_string(osd_login_prog, osd_login_prog, sizeof(osd_login_prog),
+		    0600);
+MODULE_PARM_DESC(osd_login_prog, "Path to the osd_login upcall program");
+
+struct __auto_login {
+	char uri[OBJLAYOUT_MAX_URI_LEN];
+	char osdname[OBJLAYOUT_MAX_OSDNAME_LEN];
+	char systemid_hex[OBJLAYOUT_MAX_SYSID_HEX_LEN];
+};
+
+static int __objlayout_upcall(struct __auto_login *login)
+{
+	static char *envp[] = { "HOME=/",
+		"TERM=linux",
+		"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
+		NULL
+	};
+	char *argv[8];
+	int ret;
+
+	if (unlikely(!osd_login_prog[0])) {
+		dprintk("%s: osd_login_prog is disabled\n", __func__);
+		return -EACCES;
+	}
+
+	dprintk("%s uri: %s\n", __func__, login->uri);
+	dprintk("%s osdname %s\n", __func__, login->osdname);
+	dprintk("%s systemid_hex %s\n", __func__, login->systemid_hex);
+
+	argv[0] = (char *)osd_login_prog;
+	argv[1] = "-u";
+	argv[2] = login->uri;
+	argv[3] = "-o";
+	argv[4] = login->osdname;
+	argv[5] = "-s";
+	argv[6] = login->systemid_hex;
+	argv[7] = NULL;
+
+	ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
+	/*
+	 * Disable the upcall mechanism if we're getting an ENOENT or
+	 * EACCES error. The admin can re-enable it on the fly by using
+	 * sysfs to set the objlayoutdriver.osd_login_prog module parameter once
+	 * the problem has been fixed.
+	 */
+	if (ret == -ENOENT || ret == -EACCES) {
+		printk(KERN_ERR "PNFS-OBJ: %s was not found please set "
+			"objlayoutdriver.osd_login_prog kernel parameter!\n",
+			osd_login_prog);
+		osd_login_prog[0] = '\0';
+	}
+	dprintk("%s %s return value: %d\n", __func__, osd_login_prog, ret);
+
+	return ret;
+}
+
+/* Assume dest is all zeros */
+static void __copy_nfsS_and_zero_terminate(struct nfs4_string s,
+					   char *dest, int max_len,
+					   const char *var_name)
+{
+	if (!s.len)
+		return;
+
+	if (s.len >= max_len) {
+		pr_warn_ratelimited(
+			"objlayout_autologin: %s: s.len(%d) >= max_len(%d)",
+			var_name, s.len, max_len);
+		s.len = max_len - 1; /* space for null terminator */
+	}
+
+	memcpy(dest, s.data, s.len);
+}
+
+/* Assume sysid is all zeros */
+static void _sysid_2_hex(struct nfs4_string s,
+		  char sysid[OBJLAYOUT_MAX_SYSID_HEX_LEN])
+{
+	int i;
+	char *cur;
+
+	if (!s.len)
+		return;
+
+	if (s.len != OSD_SYSTEMID_LEN) {
+		pr_warn_ratelimited(
+		    "objlayout_autologin: systemid_len(%d) != OSD_SYSTEMID_LEN",
+		    s.len);
+		if (s.len > OSD_SYSTEMID_LEN)
+			s.len = OSD_SYSTEMID_LEN;
+	}
+
+	cur = sysid;
+	for (i = 0; i < s.len; i++)
+		cur = hex_byte_pack(cur, s.data[i]);
+}
+
+int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr)
+{
+	int rc;
+	struct __auto_login login;
+
+	if (!deviceaddr->oda_targetaddr.ota_netaddr.r_addr.len)
+		return -ENODEV;
+
+	memset(&login, 0, sizeof(login));
+	__copy_nfsS_and_zero_terminate(
+		deviceaddr->oda_targetaddr.ota_netaddr.r_addr,
+		login.uri, sizeof(login.uri), "URI");
+
+	__copy_nfsS_and_zero_terminate(
+		deviceaddr->oda_osdname,
+		login.osdname, sizeof(login.osdname), "OSDNAME");
+
+	_sysid_2_hex(deviceaddr->oda_systemid, login.systemid_hex);
+
+	rc = __objlayout_upcall(&login);
+	if (rc > 0) /* script returns positive values */
+		rc = -ENODEV;
+
+	return rc;
+}
diff --git a/fs/nfs/objlayout/objlayout.h b/fs/nfs/objlayout/objlayout.h
index 8ec3472..880ba08 100644
--- a/fs/nfs/objlayout/objlayout.h
+++ b/fs/nfs/objlayout/objlayout.h
@@ -184,4 +184,6 @@ extern void objlayout_encode_layoutreturn(
 	struct xdr_stream *,
 	const struct nfs4_layoutreturn_args *);
 
+extern int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr);
+
 #endif /* _OBJLAYOUT_H */
-- 
1.7.6.5



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* SQUASHME: osd_login: Add autologin script for objlayoutdriver
  2012-03-16  6:27 ` [PATCH 4/4] osd_login: Add autologin script for objlayoutdriver Boaz Harrosh
@ 2012-03-23  2:36   ` Boaz Harrosh
  2012-03-23  2:57   ` [PATCH version2] " Boaz Harrosh
  2012-05-01 18:50   ` [PATCH 4/4] " Steve Dickson
  2 siblings, 0 replies; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-23  2:36 UTC (permalink / raw)
  To: Steve Dickson, Bhamare, Sachin, Trond Myklebust
  Cc: NFS list, open-osd, Benny Halevy, Welch, Brent

On 03/15/2012 11:27 PM, Boaz Harrosh wrote:
> From: Sachin Bhamare <sbhamare@panasas.com>
> 
> This script is part of the autologin feature mandated by the
> pnfs-objects standard.
> It is called from objlayoutdriver.ko in the kernel.
> 
> Signed-off-by: Sachin Bhamare <sbhamare@panasas.com>
> Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>

As suggested by Trond (Thanks Trond) We add a watchdog
facility to the script so it will timeout after 15s and
will return to the Kernel, even if iscsiadm gets stuck.

We are also logging with the "osd_login" prefix.

Below is the diff from this patch. (ver 1).

I will send a new email patch [version 2] for submission
to nfs-utils, as reply to the original patch.

Please submit, as the Kernel part has been accepted
into Mainline for the 3.4-rc1 merge window

Much obliged
Sachin & Boaz

---
diff --git a/utils/osd_login/osd_login b/utils/osd_login/osd_login
index c08e05c..63967fc 100755
--- a/utils/osd_login/osd_login
+++ b/utils/osd_login/osd_login
@@ -27,6 +27,9 @@ PATH="/sbin:/usr/sbin:/bin:/usr/bin"
 
 iscsiadm=/sbin/iscsiadm
 
+PARENT_PID=$BASHPID
+WATCHDOG_TIMEOUT=15
+
 protocol=""
 portal=""
 uri=""
@@ -71,32 +74,45 @@ parse_cmdline()
 	portal=`echo $uri | awk -F '//' '{print $2}'`
 }
 
-do_cmd()
+watchdog()
 {
-	$* 2>&1 | logger &
+	timeout=$1
+	portal=$2
+
+        sleep $timeout
+	if kill -9 $PARENT_PID; then
+	    echo "watchdog : Timed out (>$timeout seconds) while login into $portal" | logger -t "osd_login"
+	fi
+        echo "watchdog: exiting .."
+        exit 2
 }
 
 login_iscsi_osd()
 {
-	echo "osd_login: login into: $1"
+	echo "login into: $1"
 	if ! $iscsiadm -m discovery -o nonpersistent -t sendtargets -p $1 --login; then
 		echo "$iscsiadm -m discovery -t sendtargets -p $1 --login returned error $? !"
 		sleep 1;
 	fi
 }
 
- echo "============= osd_login ========="
- echo "progname : $0"
+echo "============= osd_login ========="
+echo "progname : $0"
 parse_cmdline "$@"
 echo "protocol: $protocol"
 echo "portal: $portal"
 
+watchdog $WATCHDOG_TIMEOUT $portal &
+watchdog_pid=$!
+
 case $protocol in
 iscsi)
-	login_iscsi_osd $portal |& logger
+	login_iscsi_osd $portal |& logger -t "osd_login"
 	;;
 *)
-	echo "osd_login: Error: protocol $protocol not supported !" | logger
+	echo "Error: protocol $protocol not supported !" | logger -t "osd_login"
 	;;
 esac
 
+kill -9 $watchdog_pid
+exit 0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH version2] osd_login: Add autologin script for objlayoutdriver.
  2012-03-16  6:27 ` [PATCH 4/4] osd_login: Add autologin script for objlayoutdriver Boaz Harrosh
  2012-03-23  2:36   ` SQUASHME: " Boaz Harrosh
@ 2012-03-23  2:57   ` Boaz Harrosh
  2012-05-01 18:50   ` [PATCH 4/4] " Steve Dickson
  2 siblings, 0 replies; 17+ messages in thread
From: Boaz Harrosh @ 2012-03-23  2:57 UTC (permalink / raw)
  To: Steve Dickson, Bhamare, Sachin, Trond Myklebust
  Cc: NFS list, open-osd, Benny Halevy, Welch, Brent

From: Sachin Bhamare <sbhamare@panasas.com>

This script is part of the autologin feature mandated by the
pnfs-objects standard.
It is called from objlayoutdriver.ko in the kernel.

It invokes iscsiadm program to perform the iscsi login to OSDs.
It also features a watchdog which will make sure that control
returns to kernel after 15s timeout.

Signed-off-by: Sachin Bhamare <sbhamare@panasas.com>
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
 configure.ac                |    1 +
 utils/Makefile.am           |    1 +
 utils/osd_login/Makefile.am |   13 +++++
 utils/osd_login/osd_login   |  118 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 133 insertions(+), 0 deletions(-)
 create mode 100644 utils/osd_login/Makefile.am
 create mode 100755 utils/osd_login/osd_login

diff --git a/configure.ac b/configure.ac
index 67e8d2d..011a2bf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -467,6 +467,7 @@ AC_CONFIG_FILES([
 	utils/nfsidmap/Makefile
 	utils/showmount/Makefile
 	utils/statd/Makefile
+	utils/osd_login/Makefile
 	tests/Makefile
 	tests/nsm_client/Makefile])
 AC_OUTPUT
diff --git a/utils/Makefile.am b/utils/Makefile.am
index d074b85..c7e5d27 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -28,6 +28,7 @@ SUBDIRS = \
 	nfsstat \
 	showmount \
 	statd \
+	osd_login \
 	$(OPTDIRS)
 
 MAINTAINERCLEANFILES = Makefile.in
diff --git a/utils/osd_login/Makefile.am b/utils/osd_login/Makefile.am
new file mode 100644
index 0000000..e931e36
--- /dev/null
+++ b/utils/osd_login/Makefile.am
@@ -0,0 +1,12 @@
+## Process this file with automake to produce Makefile.in
+
+OSD_LOGIN_FILES= osd_login
+
+EXTRA_DIST= $(OSD_LOGIN_FILES)
+
+all-local: $(OSD_LOGIN_FILES)
+
+install-data-hook:
+	$(INSTALL) --mode 755 osd_login $(DESTDIR)/sbin/osd_login
+
+MAINTAINERCLEANFILES = Makefile.in
diff --git a/utils/osd_login/osd_login b/utils/osd_login/osd_login
new file mode 100755
index 0000000..63967fc
--- /dev/null
+++ b/utils/osd_login/osd_login
@@ -0,0 +1,118 @@
+#!/bin/bash
+#
+# osd_login : This script is part of the autologin feature
+#             mandated by the pnfs-objects standard.
+# It is called from objlayoutdriver.ko in the kernel.
+
+# Copyright (C) 2012, Sachin Bhamare <sbhamare@panasas.com>
+# Copyright (C) 2012, Boaz Harrosh <bharrosh@panasas.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301 USA
+
+umask 022
+
+PATH="/sbin:/usr/sbin:/bin:/usr/bin"
+
+iscsiadm=/sbin/iscsiadm
+
+PARENT_PID=$BASHPID
+WATCHDOG_TIMEOUT=15
+
+protocol=""
+portal=""
+uri=""
+osdname=""
+systemid=""
+
+usage()
+{
+	echo "Usage: $0 -u <URI> -o <OSDNAME> -s <SYSTEMID>"
+	echo "Options:"
+	echo  "-u		target uri e.g. iscsi://<ip>:<port>"
+	echo  "-o		osdname of the target OSD"
+	echo  "-s		systemid of the target OSD"
+}
+
+parse_cmdline()
+{
+	argc=$#
+	if [ $# -lt 3 ]; then
+		usage
+		exit 1
+	fi
+
+	# parse the input arguments
+	while getopts "u:o:s:" options; do
+	    case $options in
+		u ) uri=$OPTARG;;
+		o ) osdname=$OPTARG;;
+		s ) systemid=$OPTARG;;
+		\? ) usage
+			exit 1;;
+		* )  usage
+			exit 1;;
+	    esac
+	done
+
+	echo "-u : $uri"
+	echo "-o : $osdname"
+	echo "-s : $systemid"
+
+	protocol=`echo $uri | awk -F ':' '{print $1}'`
+	portal=`echo $uri | awk -F '//' '{print $2}'`
+}
+
+watchdog()
+{
+	timeout=$1
+	portal=$2
+
+	sleep $timeout
+	if kill -9 $PARENT_PID; then
+	    echo "watchdog : Timed out (>$timeout seconds) while login into $portal" | logger -t "osd_login"
+	fi
+	echo "watchdog: exiting .."
+	exit 2
+}
+
+login_iscsi_osd()
+{
+	echo "login into: $1"
+	if ! $iscsiadm -m discovery -o nonpersistent -t sendtargets -p $1 --login; then
+		echo "$iscsiadm -m discovery -t sendtargets -p $1 --login returned error $? !"
+		sleep 1;
+	fi
+}
+
+echo "============= osd_login ========="
+echo "progname : $0"
+parse_cmdline "$@"
+echo "protocol: $protocol"
+echo "portal: $portal"
+
+watchdog $WATCHDOG_TIMEOUT $portal &
+watchdog_pid=$!
+
+case $protocol in
+iscsi)
+	login_iscsi_osd $portal |& logger -t "osd_login"
+	;;
+*)
+	echo "Error: protocol $protocol not supported !" | logger -t "osd_login"
+	;;
+esac
+
+kill -9 $watchdog_pid
+exit 0
-- 
1.7.6.2



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/4] osd_login: Add autologin script for objlayoutdriver
  2012-03-16  6:27 ` [PATCH 4/4] osd_login: Add autologin script for objlayoutdriver Boaz Harrosh
  2012-03-23  2:36   ` SQUASHME: " Boaz Harrosh
  2012-03-23  2:57   ` [PATCH version2] " Boaz Harrosh
@ 2012-05-01 18:50   ` Steve Dickson
  2 siblings, 0 replies; 17+ messages in thread
From: Steve Dickson @ 2012-05-01 18:50 UTC (permalink / raw)
  To: Boaz Harrosh
  Cc: NFS list, open-osd, Bhamare, Sachin, Trond Myklebust,
	Benny Halevy, Welch, Brent



On 03/16/2012 02:27 AM, Boaz Harrosh wrote:
> From: Sachin Bhamare <sbhamare@panasas.com>
> 
> This script is part of the autologin feature mandated by the
> pnfs-objects standard.
> It is called from objlayoutdriver.ko in the kernel.
> 
> Signed-off-by: Sachin Bhamare <sbhamare@panasas.com>
> Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
Committed...

steved.
> ---
>  configure.ac                |    1 +
>  utils/Makefile.am           |    1 +
>  utils/osd_login/Makefile.am |   13 +++++
>  utils/osd_login/osd_login   |  102 +++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 117 insertions(+), 0 deletions(-)
>  create mode 100644 utils/osd_login/Makefile.am
>  create mode 100755 utils/osd_login/osd_login
> 
> diff --git a/configure.ac b/configure.ac
> index 67e8d2d..011a2bf 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -467,6 +467,7 @@ AC_CONFIG_FILES([
>  	utils/nfsidmap/Makefile
>  	utils/showmount/Makefile
>  	utils/statd/Makefile
> +	utils/osd_login/Makefile
>  	tests/Makefile
>  	tests/nsm_client/Makefile])
>  AC_OUTPUT
> diff --git a/utils/Makefile.am b/utils/Makefile.am
> index d074b85..c7e5d27 100644
> --- a/utils/Makefile.am
> +++ b/utils/Makefile.am
> @@ -28,6 +28,7 @@ SUBDIRS = \
>  	nfsstat \
>  	showmount \
>  	statd \
> +	osd_login \
>  	$(OPTDIRS)
>  
>  MAINTAINERCLEANFILES = Makefile.in
> diff --git a/utils/osd_login/Makefile.am b/utils/osd_login/Makefile.am
> new file mode 100644
> index 0000000..e931e36
> --- /dev/null
> +++ b/utils/osd_login/Makefile.am
> @@ -0,0 +1,13 @@
> +## Process this file with automake to produce Makefile.in
> +
> +OSD_LOGIN_FILES= osd_login
> +
> +EXTRA_DIST= $(OSD_LOGIN_FILES)
> +
> +all-local: $(OSD_LOGIN_FILES)
> +
> +install-data-hook:
> +	$(INSTALL) --mode 755 osd_login $(DESTDIR)/sbin/osd_login
> +
> +MAINTAINERCLEANFILES = Makefile.in
> +
> diff --git a/utils/osd_login/osd_login b/utils/osd_login/osd_login
> new file mode 100755
> index 0000000..161a487
> --- /dev/null
> +++ b/utils/osd_login/osd_login
> @@ -0,0 +1,102 @@
> +#!/bin/bash
> +#
> +# osd_login : This script is part of the autologin feature
> +#             mandated by the pnfs-objects standard.
> +# It is called from objlayoutdriver.ko in the kernel.
> +
> +# Copyright (C) 2012, Sachin Bhamare <sbhamare@panasas.com>
> +# Copyright (C) 2012, Boaz Harrosh <bharrosh@panasas.com>
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License version 2 as
> +# published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> +# MA 02110-1301 USA
> +
> +umask 022
> +
> +PATH="/sbin:/usr/sbin:/bin:/usr/bin"
> +
> +iscsiadm=/sbin/iscsiadm
> +
> +protocol=""
> +portal=""
> +uri=""
> +osdname=""
> +systemid=""
> +
> +usage()
> +{
> +	echo "Usage: $0 -u <URI> -o <OSDNAME> -s <SYSTEMID>"
> +	echo "Options:"
> +	echo  "-u		target uri e.g. iscsi://<ip>:<port>"
> +	echo  "-o		osdname of the target OSD"
> +	echo  "-s 		systemid of the target OSD"
> +}
> +
> +parse_cmdline()
> +{
> +	argc=$#
> +	if [ $# -lt 3 ]; then
> +		usage
> +		exit 1
> +	fi
> +
> +	# parse the input arguments
> +	while getopts "u:o:s:" options; do
> +	    case $options in
> +		u ) uri=$OPTARG;;
> +		o ) osdname=$OPTARG;;
> +		s ) systemid=$OPTARG;;
> +		\? ) usage
> +			exit 1;;
> +		* )  usage
> +			exit 1;;
> +	    esac
> +	done
> +
> +	echo "-u : $uri"
> +	echo "-o : $osdname"
> +	echo "-s : $systemid"
> +
> +	protocol=`echo $uri | awk -F ':' '{print $1}'`
> +	portal=`echo $uri | awk -F '//' '{print $2}'`
> +}
> +
> +do_cmd()
> +{
> +	$* 2>&1 | logger &
> +}
> +
> +login_iscsi_osd()
> +{
> +	echo "osd_login: login into: $1"
> +	if ! $iscsiadm -m discovery -o nonpersistent -t sendtargets -p $1 --login; then
> +		echo "$iscsiadm -m discovery -t sendtargets -p $1 --login returned error $? !"
> +		sleep 1;
> +	fi
> +}
> +
> + echo "============= osd_login ========="
> + echo "progname : $0"
> +parse_cmdline "$@"
> +echo "protocol: $protocol"
> +echo "portal: $portal"
> +
> +case $protocol in
> +iscsi)
> +	login_iscsi_osd $portal |& logger
> +	;;
> +*)
> +	echo "osd_login: Error: protocol $protocol not supported !" | logger
> +	;;
> +esac
> +

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-05-01 18:59 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-16  6:17 [PATCHSET 0/4] Auto-login support for the pnfs-objects protocol Boaz Harrosh
2012-03-16  6:19 ` [PATCH 1/4] pnfsd-exofs: Add autologin support to exofs Boaz Harrosh
2012-03-16  6:30   ` Boaz Harrosh
2012-03-16  6:21 ` [PATCH 2/4] pnfs-obj: Remove unused variable from objlayout_get_deviceinfo() Boaz Harrosh
2012-03-16  6:23 ` [PATCH 3/4] pnfs-obj: autologin: Add support for protocol autologin Boaz Harrosh
2012-03-16 21:40   ` Myklebust, Trond
2012-03-19 20:58     ` Boaz Harrosh
2012-03-19 21:12       ` Myklebust, Trond
2012-03-19 23:23         ` Boaz Harrosh
2012-03-20  1:16           ` Boaz Harrosh
2012-03-20  3:10             ` Boaz Harrosh
2012-03-20  3:26               ` Boaz Harrosh
2012-03-20  3:47   ` [PATCH version2] " Boaz Harrosh
2012-03-16  6:27 ` [PATCH 4/4] osd_login: Add autologin script for objlayoutdriver Boaz Harrosh
2012-03-23  2:36   ` SQUASHME: " Boaz Harrosh
2012-03-23  2:57   ` [PATCH version2] " Boaz Harrosh
2012-05-01 18:50   ` [PATCH 4/4] " Steve Dickson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.