From patchwork Thu May 11 14:01:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 9722545 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CA1E6601E7 for ; Thu, 11 May 2017 16:32:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE52C280FC for ; Thu, 11 May 2017 16:32:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B166528683; Thu, 11 May 2017 16:32:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6759E280FC for ; Thu, 11 May 2017 16:32:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757318AbdEKQcP (ORCPT ); Thu, 11 May 2017 12:32:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54770 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933162AbdEKOBM (ORCPT ); Thu, 11 May 2017 10:01:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BE362560; Thu, 11 May 2017 14:01:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9BE362560 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dhowells@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9BE362560 Received: from warthog.procyon.org.uk (ovpn-120-67.rdu2.redhat.com [10.10.120.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 597EA8A8C0; Thu, 11 May 2017 14:01:10 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 09/14] Sample program for driving fsopen/fsmount [ver #2] From: David Howells To: mszeredi@redhat.com, viro@zeniv.linux.org.uk, jlayton@redhat.com Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 11 May 2017 15:01:09 +0100 Message-ID: <149451126956.4599.12260848111783654296.stgit@warthog.procyon.org.uk> In-Reply-To: <149451118535.4599.16084557087363834548.stgit@warthog.procyon.org.uk> References: <149451118535.4599.16084557087363834548.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 11 May 2017 14:01:11 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP --- samples/fsmount/test-fsmount.c | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 samples/fsmount/test-fsmount.c --- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/samples/fsmount/test-fsmount.c b/samples/fsmount/test-fsmount.c new file mode 100644 index 000000000000..98b0258ae08f --- /dev/null +++ b/samples/fsmount/test-fsmount.c @@ -0,0 +1,79 @@ +/* fd-based mount test. + * + * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowells@redhat.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public Licence + * as published by the Free Software Foundation; either version + * 2 of the Licence, or (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include + +#define E(x) do { if ((x) == -1) { perror(#x); exit(1); } } while(0) + +static __attribute__((noreturn)) +void mount_error(int fd, const char *s) +{ + char buf[4096]; + int err, n; + + err = errno; + n = read(fd, buf, sizeof(buf)); + errno = err; + if (n > 0) { + n -= 2; + fprintf(stderr, "Error: '%s': %*.*s: %m\n", s, n, n, buf + 2); + } else { + fprintf(stderr, "%s: %m\n", s); + } + exit(1); +} + +#define E_write(fd, s) \ + do { \ + if (write(fd, s, sizeof(s) - 1) == -1) \ + mount_error(fd, s); \ + } while (0) + +static inline int fsopen(const char *fs_name, int reserved, int flags) +{ + return syscall(333, fs_name, reserved, flags); +} + +static inline int fsmount(int fsfd, int dfd, const char *path, + unsigned int at_flags, unsigned int flags) +{ + return syscall(334, fsfd, dfd, path, at_flags, flags); +} + +int main() +{ + int mfd; + + /* Mount an NFS filesystem */ + mfd = fsopen("nfs4", -1, 0); + if (mfd == -1) { + perror("fsopen"); + exit(1); + } + + E_write(mfd, "s warthog:/data"); + E_write(mfd, "o fsc"); + E_write(mfd, "o sync"); + E_write(mfd, "o intr"); + E_write(mfd, "o vers=4.2"); + E_write(mfd, "o addr=90.155.74.18"); + E_write(mfd, "o clientaddr=90.155.74.21"); + if (fsmount(mfd, AT_FDCWD, "/mnt", 0, 0) < 0) + mount_error(mfd, "fsmount"); + E(close(mfd)); + + exit(0); +}