From owner-svn-src-projects@freebsd.org Fri Apr 28 22:49:38 2017 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C9C88D5544F for ; Fri, 28 Apr 2017 22:49:38 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A228365F; Fri, 28 Apr 2017 22:49:38 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3SMnbMp005304; Fri, 28 Apr 2017 22:49:37 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3SMnb3Q005302; Fri, 28 Apr 2017 22:49:37 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201704282249.v3SMnb3Q005302@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Fri, 28 Apr 2017 22:49:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r317574 - in projects/pnfs-planb-server/usr.bin: . pnfsdsfile X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Apr 2017 22:49:38 -0000 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 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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); +} +