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

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