Blame SOURCES/nfs-utils-1.3.0-blkmapd-pnfs.patch

e19a30
diff --git a/Makefile.am b/Makefile.am
e19a30
index ae7cd16..c9e9f87 100644
e19a30
--- a/Makefile.am
e19a30
+++ b/Makefile.am
e19a30
@@ -2,7 +2,7 @@
e19a30
 
e19a30
 AUTOMAKE_OPTIONS = foreign
e19a30
 
e19a30
-SUBDIRS = tools support utils linux-nfs tests
e19a30
+SUBDIRS = tools support utils linux-nfs tests systemd
e19a30
 
e19a30
 MAINTAINERCLEANFILES = Makefile.in
e19a30
 
e19a30
diff --git a/configure.ac b/configure.ac
e19a30
index 7b93de6..4ee4db5 100644
e19a30
--- a/configure.ac
e19a30
+++ b/configure.ac
e19a30
@@ -54,6 +54,16 @@ AC_ARG_WITH(start-statd,
e19a30
 	)
e19a30
 	AC_SUBST(startstatd)
e19a30
 	AC_DEFINE_UNQUOTED(START_STATD, "$startstatd", [Define this to a script which can start statd on mount])
e19a30
+unitdir=/usr/lib/systemd/system
e19a30
+AC_ARG_WITH(systemd,
e19a30
+	[AC_HELP_STRING([--with-systemd@<:@=unit-dir-path@:>@],
e19a30
+			[install systemd unit files @<:@Default: no, and path defaults to /usr/lib/systemd/system if not given@:>@])],
e19a30
+	test "$withval" = "no" && use_systemd=0 || unitdir=$withval use_systemd=1
e19a30
+	use_systemd=0
e19a30
+	)
e19a30
+	AM_CONDITIONAL(INSTALL_SYSTEMD, [test "$use_systemd" = 1])
e19a30
+	AC_SUBST(unitdir)
e19a30
+
e19a30
 AC_ARG_ENABLE(nfsv4,
e19a30
 	[AC_HELP_STRING([--enable-nfsv4],
e19a30
                         [enable support for NFSv4 @<:@default=yes@:>@])],
e19a30
@@ -506,6 +516,7 @@ AC_CONFIG_FILES([
e19a30
 	utils/showmount/Makefile
e19a30
 	utils/statd/Makefile
e19a30
 	utils/osd_login/Makefile
e19a30
+	systemd/Makefile
e19a30
 	tests/Makefile
e19a30
 	tests/nsm_client/Makefile])
e19a30
 AC_OUTPUT
e19a30
diff --git a/support/include/nfs/export.h b/support/include/nfs/export.h
e19a30
index 2f59e6a..1194255 100644
e19a30
--- a/support/include/nfs/export.h
e19a30
+++ b/support/include/nfs/export.h
e19a30
@@ -26,6 +26,7 @@
e19a30
 #define	NFSEXP_CROSSMOUNT	0x4000
e19a30
 #define NFSEXP_NOACL		0x8000 /* reserved for possible ACL related use */
e19a30
 #define NFSEXP_V4ROOT		0x10000
e19a30
+#define NFSEXP_PNFS            0x20000
e19a30
 /*
e19a30
  * All flags supported by the kernel before addition of the
e19a30
  * export_features interface:
e19a30
diff --git a/support/nfs/exports.c b/support/nfs/exports.c
e19a30
index 5451ed7..9399a12 100644
e19a30
--- a/support/nfs/exports.c
e19a30
+++ b/support/nfs/exports.c
e19a30
@@ -275,6 +275,7 @@ putexportent(struct exportent *ep)
e19a30
 		"no_" : "");
e19a30
 	if (ep->e_flags & NFSEXP_NOREADDIRPLUS)
e19a30
 		fprintf(fp, "nordirplus,");
e19a30
+	fprintf(fp, "%spnfs,", (ep->e_flags & NFSEXP_PNFS)? "" : "no_");
e19a30
 	if (ep->e_flags & NFSEXP_FSID) {
e19a30
 		fprintf(fp, "fsid=%d,", ep->e_fsid);
e19a30
 	}
e19a30
@@ -581,6 +582,10 @@ parseopts(char *cp, struct exportent *ep, int warn, int *had_subtree_opt_ptr)
e19a30
 			clearflags(NFSEXP_NOACL, active, ep);
e19a30
 		else if (strcmp(opt, "no_acl") == 0)
e19a30
 			setflags(NFSEXP_NOACL, active, ep);
e19a30
+		else if (!strcmp(opt, "pnfs"))
e19a30
+			setflags(NFSEXP_PNFS, active, ep);
e19a30
+		else if (!strcmp(opt, "no_pnfs"))
e19a30
+			clearflags(NFSEXP_PNFS, active, ep);
e19a30
 		else if (strncmp(opt, "anonuid=", 8) == 0) {
e19a30
 			char *oe;
e19a30
 			ep->e_anonuid = strtol(opt+8, &oe, 10);
e19a30
diff --git a/systemd/Makefile.am b/systemd/Makefile.am
e19a30
new file mode 100644
e19a30
index 0000000..fbcabb1
e19a30
--- /dev/null
e19a30
+++ b/systemd/Makefile.am
e19a30
@@ -0,0 +1,31 @@
e19a30
+## Process this file with automake to produce Makefile.in
e19a30
+
e19a30
+MAINTAINERCLEANFILES = Makefile.in
e19a30
+
e19a30
+unit_files =  \
e19a30
+    nfs-client.target \
e19a30
+    \
e19a30
+    auth-rpcgss-module.service \
e19a30
+    nfs-blkmap.service \
e19a30
+    nfs-config.service \
e19a30
+    nfs-idmapd.service \
e19a30
+    nfs-mountd.service \
e19a30
+    nfs-server.service \
e19a30
+    nfs-utils.service \
e19a30
+    rpc-gssd.service \
e19a30
+    rpc-statd-notify.service \
e19a30
+    rpc-statd.service \
e19a30
+    rpc-svcgssd.service \
e19a30
+    \
e19a30
+    proc-fs-nfsd.mount \
e19a30
+    var-lib-nfs-rpc_pipefs.mount
e19a30
+
e19a30
+EXTRA_DIST = $(unit_files)
e19a30
+
e19a30
+unit_dir = /usr/lib/systemd/system
e19a30
+
e19a30
+if INSTALL_SYSTEMD
e19a30
+install-data-hook: $(unit_files)
e19a30
+	mkdir -p $(DESTDIR)/$(unitdir)
e19a30
+	cp $(unit_files) $(DESTDIR)/$(unitdir)
e19a30
+endif
e19a30
diff --git a/systemd/README b/systemd/README
e19a30
index a2a5f06..bbd7790 100644
e19a30
--- a/systemd/README
e19a30
+++ b/systemd/README
e19a30
@@ -24,7 +24,7 @@ by a suitable 'preset' setting:
e19a30
     is started by /usr/sbin/start-statd which mount.nfs will run
e19a30
     if statd is needed.
e19a30
 
e19a30
- nfs-blkmap.target
e19a30
+ nfs-blkmap.service
e19a30
     If enabled, then blkmapd will be run when nfs-client.target is
e19a30
     started.
e19a30
 
e19a30
diff --git a/systemd/nfs-blkmap.service b/systemd/nfs-blkmap.service
e19a30
index f470e3d..ddbf4e9 100644
e19a30
--- a/systemd/nfs-blkmap.service
e19a30
+++ b/systemd/nfs-blkmap.service
e19a30
@@ -5,12 +5,13 @@ Conflicts=umount.target
e19a30
 After=var-lib-nfs-rpc_pipefs.mount
e19a30
 Requires=var-lib-nfs-rpc_pipefs.mount
e19a30
 
e19a30
-Requisite=nfs-blkmap.target
e19a30
-After=nfs-blkmap.target
e19a30
-
e19a30
 PartOf=nfs-utils.service
e19a30
 
e19a30
 [Service]
e19a30
 Type=forking
e19a30
 PIDFile=/var/run/blkmapd.pid
e19a30
+EnvironmentFile=-/run/sysconfig/nfs-utils
e19a30
 ExecStart=/usr/sbin/blkmapd $BLKMAPDARGS
e19a30
+
e19a30
+[Install]
e19a30
+WantedBy=nfs-client.target
e19a30
diff --git a/systemd/nfs-blkmap.target b/systemd/nfs-blkmap.target
e19a30
deleted file mode 100644
e19a30
index fbcc111..0000000
e19a30
--- a/systemd/nfs-blkmap.target
e19a30
+++ /dev/null
e19a30
@@ -1,8 +0,0 @@
e19a30
-[Unit]
e19a30
-Description= PNFS blkmaping enablement.
e19a30
-# If this target is enabled, then blkmapd will be started
e19a30
-# as required.  If it is not enabled it won't.
e19a30
-
e19a30
-[Install]
e19a30
-WantedBy=remote-fs.target
e19a30
-WantedBy=multi-user.target
e19a30
\ No newline at end of file
e19a30
diff --git a/systemd/nfs-client.target b/systemd/nfs-client.target
e19a30
index 9b792a3..8a8300a 100644
e19a30
--- a/systemd/nfs-client.target
e19a30
+++ b/systemd/nfs-client.target
e19a30
@@ -5,8 +5,7 @@ Wants=remote-fs-pre.target
e19a30
 
e19a30
 # Note: we don't "Wants=rpc-statd.service" as "mount.nfs" will arrange to
e19a30
 # start that on demand if needed.
e19a30
-Wants=nfs-blkmap.service rpc-statd-notify.service
e19a30
-After=nfs-blkmap.service
e19a30
+Wants=rpc-statd-notify.service
e19a30
 
e19a30
 # GSS services dependencies and ordering
e19a30
 Wants=auth-rpcgss-module.service
e19a30
diff --git a/utils/blkmapd/device-discovery.c b/utils/blkmapd/device-discovery.c
e19a30
index df4627e..b52afe2 100644
e19a30
--- a/utils/blkmapd/device-discovery.c
e19a30
+++ b/utils/blkmapd/device-discovery.c
e19a30
@@ -77,16 +77,6 @@ struct bl_disk_path *bl_get_path(const char *filepath,
e19a30
 	return tmp;
e19a30
 }
e19a30
 
e19a30
-/* Check whether valid_path is a substring(partition) of path */
e19a30
-int bl_is_partition(struct bl_disk_path *valid_path, struct bl_disk_path *path)
e19a30
-{
e19a30
-	if (!strncmp(valid_path->full_path, path->full_path,
e19a30
-		     strlen(valid_path->full_path)))
e19a30
-		return 1;
e19a30
-
e19a30
-	return 0;
e19a30
-}
e19a30
-
e19a30
 /*
e19a30
  * For multipath devices, devices state could be PASSIVE/ACTIVE/PSEUDO,
e19a30
  * where PSEUDO > ACTIVE > PASSIVE. Device with highest state is used to
e19a30
@@ -95,19 +85,13 @@ int bl_is_partition(struct bl_disk_path *valid_path, struct bl_disk_path *path)
e19a30
  * If device-mapper multipath support is a must, pseudo devices should
e19a30
  * exist for each multipath device. If not, active device path will be
e19a30
  * chosen for device creation.
e19a30
- * Treat partition as invalid path.
e19a30
  */
e19a30
-int bl_update_path(struct bl_disk_path *path, enum bl_path_state_e state,
e19a30
-		   struct bl_disk *disk)
e19a30
+int bl_update_path(enum bl_path_state_e state, struct bl_disk *disk)
e19a30
 {
e19a30
 	struct bl_disk_path *valid_path = disk->valid_path;
e19a30
 
e19a30
-	if (valid_path) {
e19a30
-		if (valid_path->state >= state) {
e19a30
-			if (bl_is_partition(valid_path, path))
e19a30
-				return 0;
e19a30
-		}
e19a30
-	}
e19a30
+	if (valid_path && valid_path->state >= state)
e19a30
+		return 0;
e19a30
 	return 1;
e19a30
 }
e19a30
 
e19a30
@@ -164,15 +148,16 @@ void bl_add_disk(char *filepath)
e19a30
 
e19a30
 	dev = sb.st_rdev;
e19a30
 	serial = bldev_read_serial(fd, filepath);
e19a30
-	if (dm_is_dm_major(major(dev)))
e19a30
+	if (!serial) {
e19a30
+		BL_LOG_ERR("%s: no serial found for %s\n",
e19a30
+				 __func__, filepath);
e19a30
+		ap_state = BL_PATH_STATE_PASSIVE;
e19a30
+	} else if (dm_is_dm_major(major(dev)))
e19a30
 		ap_state = BL_PATH_STATE_PSEUDO;
e19a30
 	else
e19a30
 		ap_state = bldev_read_ap_state(fd);
e19a30
 	close(fd);
e19a30
 
e19a30
-	if (ap_state != BL_PATH_STATE_ACTIVE)
e19a30
-		return;
e19a30
-
e19a30
 	for (disk = visible_disk_list; disk != NULL; disk = disk->next) {
e19a30
 		/* Already scanned or a partition?
e19a30
 		 * XXX: if released each time, maybe not need to compare
e19a30
@@ -216,7 +201,7 @@ void bl_add_disk(char *filepath)
e19a30
 		path->next = disk->paths;
e19a30
 		disk->paths = path;
e19a30
 		/* check whether we need to update disk info */
e19a30
-		if (bl_update_path(path, path->state, disk)) {
e19a30
+		if (bl_update_path(path->state, disk)) {
e19a30
 			disk->dev = dev;
e19a30
 			disk->size = size;
e19a30
 			disk->valid_path = path;
e19a30
diff --git a/utils/blkmapd/device-inq.c b/utils/blkmapd/device-inq.c
e19a30
index eabc70c..c5bf71f 100644
e19a30
--- a/utils/blkmapd/device-inq.c
e19a30
+++ b/utils/blkmapd/device-inq.c
e19a30
@@ -179,6 +179,7 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename)
e19a30
 	char *buffer;
e19a30
 	struct bl_dev_id *dev_root, *dev_id;
e19a30
 	unsigned int pos, len, current_id = 0;
e19a30
+	size_t devid_len = sizeof(struct bl_dev_id) - sizeof(unsigned char);
e19a30
 
e19a30
 	status = bldev_inquire_pages(fd, 0x83, &buffer);
e19a30
 	if (status)
e19a30
@@ -189,7 +190,11 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename)
e19a30
 	pos = 0;
e19a30
 	current_id = 0;
e19a30
 	len = dev_root->len;
e19a30
-	while (pos < (len - sizeof(struct bl_dev_id) + sizeof(unsigned char))) {
e19a30
+
e19a30
+	if (len < devid_len)
e19a30
+		goto out;
e19a30
+
e19a30
+	while (pos < (len - devid_len)) {
e19a30
 		dev_id = (struct bl_dev_id *)&(dev_root->data[pos]);
e19a30
 		if ((dev_id->ids & 0xf) < current_id)
e19a30
 			continue;
e19a30
@@ -221,8 +226,7 @@ struct bl_serial *bldev_read_serial(int fd, const char *filename)
e19a30
 		}
e19a30
 		if (current_id == 3)
e19a30
 			break;
e19a30
-		pos += (dev_id->len + sizeof(struct bl_dev_id) -
e19a30
-			sizeof(unsigned char));
e19a30
+		pos += (dev_id->len + devid_len);
e19a30
 	}
e19a30
  out:
e19a30
 	if (!serial_out)
e19a30
diff --git a/utils/blkmapd/device-process.c b/utils/blkmapd/device-process.c
e19a30
index 5fe3dff..f53a616 100644
e19a30
--- a/utils/blkmapd/device-process.c
e19a30
+++ b/utils/blkmapd/device-process.c
e19a30
@@ -181,6 +181,8 @@ static int map_sig_to_device(struct bl_sig *sig, struct bl_volume *vol)
e19a30
 		/* FIXME: should we use better algorithm for disk scan? */
e19a30
 		mapped = verify_sig(disk, sig);
e19a30
 		if (mapped) {
e19a30
+			BL_LOG_INFO("%s: using device %s\n",
e19a30
+					__func__, disk->valid_path->full_path);
e19a30
 			vol->param.bv_dev = disk->dev;
e19a30
 			vol->bv_size = disk->size;
e19a30
 			break;
e19a30
diff --git a/utils/blkmapd/dm-device.c b/utils/blkmapd/dm-device.c
e19a30
index 0f4f148..24ffcbf 100644
e19a30
--- a/utils/blkmapd/dm-device.c
e19a30
+++ b/utils/blkmapd/dm-device.c
e19a30
@@ -400,6 +400,8 @@ uint64_t dm_device_create(struct bl_volume *vols, int num_vols)
e19a30
 			}
e19a30
 			dev = node->bv_vols[0]->param.bv_dev;
e19a30
 			tmp = table->params;
e19a30
+			BL_LOG_INFO("%s: major %lu minor %lu", __func__,
e19a30
+					MAJOR(dev), MINOR(dev));
e19a30
 			if (!dm_format_dev(tmp, DM_PARAMS_LEN,
e19a30
 					   MAJOR(dev), MINOR(dev))) {
e19a30
 				free(table);
e19a30
@@ -459,6 +461,8 @@ uint64_t dm_device_create(struct bl_volume *vols, int num_vols)
e19a30
 				strcpy(table->target_type, "linear");
e19a30
 				tmp = table->params;
e19a30
 				dev = node->bv_vols[i]->param.bv_dev;
e19a30
+				BL_LOG_INFO("%s: major %lu minor %lu", __func__,
e19a30
+					MAJOR(dev), MINOR(dev));
e19a30
 				if (!dm_format_dev(tmp, DM_PARAMS_LEN,
e19a30
 						   MAJOR(dev), MINOR(dev))) {
e19a30
 					free(table);
e19a30
diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
e19a30
index 8391615..53e86ec 100644
e19a30
--- a/utils/exportfs/exportfs.c
e19a30
+++ b/utils/exportfs/exportfs.c
e19a30
@@ -815,6 +815,8 @@ dump(int verbose, int export_format)
e19a30
 				c = dumpopt(c, "insecure_locks");
e19a30
 			if (ep->e_flags & NFSEXP_NOACL)
e19a30
 				c = dumpopt(c, "no_acl");
e19a30
+			if (ep->e_flags & NFSEXP_PNFS)
e19a30
+				c = dumpopt(c, "pnfs");
e19a30
 			if (ep->e_flags & NFSEXP_FSID)
e19a30
 				c = dumpopt(c, "fsid=%d", ep->e_fsid);
e19a30
 			if (ep->e_uuid)
e19a30
diff --git a/utils/exportfs/exports.man b/utils/exportfs/exports.man
e19a30
index 3d974d9..59358e6 100644
e19a30
--- a/utils/exportfs/exports.man
e19a30
+++ b/utils/exportfs/exports.man
e19a30
@@ -378,6 +378,15 @@ If the client asks for alternative locations for the export point, it
e19a30
 will be given this list of alternatives. (Note that actual replication
e19a30
 of the filesystem must be handled elsewhere.)
e19a30
 
e19a30
+.TP
e19a30
+.IR pnfs
e19a30
+This option allows enables the use of pNFS extension if protocol level
e19a30
+is NFSv4.1 or higher, and the filesystem supports pNFS exports.  With
e19a30
+pNFS clients can bypass the server and perform I/O directly to storage
e19a30
+devices. The default can be explicitly requested with the
e19a30
+.I no_pnfs
e19a30
+option.
e19a30
+
e19a30
 .SS User ID Mapping
e19a30
 .PP
e19a30
 .B nfsd