svn commit: r319839 - in projects/pnfs-planb-server-stable11/usr.bin: . pnfsdsfile
Rick Macklem
rmacklem at FreeBSD.org
Sun Jun 11 22:14:34 UTC 2017
Author: rmacklem
Date: Sun Jun 11 22:14:32 2017
New Revision: 319839
URL: https://svnweb.freebsd.org/changeset/base/319839
Log:
Add the pnfsdsfile command to the pNFS server tree.
Added:
projects/pnfs-planb-server-stable11/usr.bin/
projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/
projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/Makefile (contents, props changed)
projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/pnfsdsfile.1 (contents, props changed)
projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/pnfsdsfile.c (contents, props changed)
Added: projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/Makefile Sun Jun 11 22:14:32 2017 (r319839)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+PROG= pnfsdsfile
+
+.include <bsd.prog.mk>
Added: projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/pnfsdsfile.1
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/pnfsdsfile.1 Sun Jun 11 22:14:32 2017 (r319839)
@@ -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-stable11/usr.bin/pnfsdsfile/pnfsdsfile.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/pnfsdsfile.c Sun Jun 11 22:14:32 2017 (r319839)
@@ -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);
+}
+
More information about the svn-src-projects
mailing list