Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Apr 2017 22:49:37 +0000 (UTC)
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r317574 - in projects/pnfs-planb-server/usr.bin: . pnfsdsfile
Message-ID:  <201704282249.v3SMnb3Q005302@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rmacklem
Date: Fri Apr 28 22:49:37 2017
New Revision: 317574
URL: https://svnweb.freebsd.org/changeset/base/317574

Log:
  Add the pnfsdsfile command to the pNFS server source tree.

Added:
  projects/pnfs-planb-server/usr.bin/
  projects/pnfs-planb-server/usr.bin/pnfsdsfile/
  projects/pnfs-planb-server/usr.bin/pnfsdsfile/Makefile   (contents, props changed)
  projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.1   (contents, props changed)
  projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.c   (contents, props changed)

Added: projects/pnfs-planb-server/usr.bin/pnfsdsfile/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/pnfs-planb-server/usr.bin/pnfsdsfile/Makefile	Fri Apr 28 22:49:37 2017	(r317574)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+PROG=	pnfsdsfile
+
+.include <bsd.prog.mk>

Added: projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.1
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.1	Fri Apr 28 22:49:37 2017	(r317574)
@@ -0,0 +1,55 @@
+.\" Copyright (c) 2017 Rick Macklem
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd April 1, 2017
+.Dt PNFSDSFILE 1
+.Os
+.Sh NAME
+.Nm pnfsdsfile
+.Nd display
+a pNFS data storage file location
+.Sh SYNOPSIS
+.Nm
+.Ar metadata_file
+.Sh DESCRIPTION
+The
+.Nm
+command displays the location of a data storage file for a pNFS service.
+A pNFS service maintains a data storage file for each regular file on
+the MetaData Server (MDS) on one of the Data Storage (DS) servers.
+This command can be used on the MDS to find out where that data storage
+file is.
+It must be used on the MDS and the
+.Ar metadata_file
+must be a file on the exported local file system and not an NFSv4.1 mount.
+.El
+.Sh SEE ALSO
+.Xr nfsv4 4 ,
+.Xr nfsd 8
+.Sh HISTORY
+The
+.Nm
+command appeared in FreeBSD12.

Added: projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.c	Fri Apr 28 22:49:37 2017	(r317574)
@@ -0,0 +1,106 @@
+/*-
+ * Copyright (c) 2017 Rick Macklem
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <err.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/param.h>
+#include <sys/extattr.h>
+#include <sys/mount.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <fs/nfs/nfsrvstate.h>
+
+static void usage(void);
+static void nfsrv_putfhname(fhandle_t *fhp, char *bufp);
+
+/*
+ * This program displays the location information of a data storage file
+ * for a given file on a MetaData Server (MDS) in a pNFS service.  This program
+ * must be run on the MDS and the file argument must be a file in a local
+ * file system that has been exported for the pNFS service.
+ */
+int
+main(int argc, char *argv[])
+{
+	fhandle_t fh;
+	char buf[sizeof(fh) * 2 + 1], hostn[NI_MAXHOST + 1];
+	struct pnfsdsfile dsfile;
+
+	if (argc != 2)
+		usage();
+
+	/*
+	 * The file's name is a hexadecimal representation of the MetaData
+	 * Server's file handle.
+	 */
+	if (getfh(argv[1], &fh) < 0)
+		err(1, "Getfh of %s failed", argv[1]);
+	nfsrv_putfhname(&fh, buf);
+
+	/*
+	 * The host address and directory where the data storage file is
+	 * located is in the extended attribute "pnfsd.dsfile".
+	 */
+	if (extattr_get_file(argv[1], EXTATTR_NAMESPACE_SYSTEM, "pnfsd.dsfile",
+	    &dsfile, sizeof(dsfile)) != sizeof(dsfile))
+		err(1, "Can't get extattr pnfsd.dsfile\n");
+
+	/* Translate the IP address to a hostname. */
+	if (getnameinfo((struct sockaddr *)&dsfile.dsf_sin,
+	    dsfile.dsf_sin.sin_len, hostn, sizeof(hostn), NULL, 0, 0) < 0)
+		err(1, "Can't get hostname\n");
+
+	printf("%s\tds%d/%s\n", hostn, dsfile.dsf_dir, buf);
+}
+
+/*
+ * Generate a file name based on the file handle and put it in *bufp.
+ */
+static void
+nfsrv_putfhname(fhandle_t *fhp, char *bufp)
+{
+	int i;
+	uint8_t *cp;
+
+	cp = (uint8_t *)fhp;
+	for (i = 0; i < sizeof(*fhp); i++)
+		sprintf(&bufp[2 * i], "%02x", *cp++);
+}
+
+static void
+usage(void)
+{
+
+	fprintf(stderr, "pnfsdsfile [filepath]\n");
+	exit(1);
+}
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201704282249.v3SMnb3Q005302>