linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: David Howells <dhowells@redhat.com>, viro@ZenIV.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org, mszeredi@redhat.com,
	linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 07/14] VFS: Add a sample program for fsopen/fsmount [ver #6]
Date: Thu, 26 Oct 2017 13:21:53 -0400	[thread overview]
Message-ID: <1509038513.29077.31.camel@redhat.com> (raw)
In-Reply-To: <150730500019.6182.15975727444128962384.stgit@warthog.procyon.org.uk>

On Fri, 2017-10-06 at 16:50 +0100, David Howells wrote:
> Add a sample program for driving fsopen/fsmount.
> 
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
> 
>  samples/fsmount/test-fsmount.c |   94 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 94 insertions(+)
>  create mode 100644 samples/fsmount/test-fsmount.c
> 
> diff --git a/samples/fsmount/test-fsmount.c b/samples/fsmount/test-fsmount.c
> new file mode 100644
> index 000000000000..75f91d272a19
> --- /dev/null
> +++ b/samples/fsmount/test-fsmount.c
> @@ -0,0 +1,94 @@
> +/* 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 <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <sys/prctl.h>
> +#include <sys/wait.h>
> +
> +#define PR_ERRMSG_ENABLE		48
> +#define PR_ERRMSG_READ			49
> +
> +#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, perr;
> +
> +	do {
> +		err = errno;
> +		errno = 0;
> +		n = prctl(PR_ERRMSG_READ, buf, sizeof(buf));
> +		perr = errno;
> +		errno = err;
> +		if (n > 0) {
> +			fprintf(stderr, "Error: '%s': %*.*s: %m\n", s, n, n, buf);
> +		} else {
> +			fprintf(stderr, "%s: %m\n", s);
> +		}
> +	} while (perr == 0);
> +	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 flags,
> +			 void *reserved3, void *reserved4, void *reserved5);
> +
> +{
> +	return syscall(333, fs_name, flags, reserved3, reserved4, reserved5);
> +}
> +
> +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;
> +
> +	if (prctl(PR_ERRMSG_ENABLE, 1) < 0) {
> +		perror("prctl/en");
> +		exit(1);
> +	}
> +
> +	/* Mount an NFS filesystem */
> +	mfd = fsopen("nfs4", 0, NULL, NULL, NULL);
> +	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");
> +	E_write(mfd, "x create");
> +	if (fsmount(mfd, AT_FDCWD, "/mnt", 0, 0) < 0)
> +		mount_error(mfd, "fsmount");
> +	E(close(mfd));
> +
> +	exit(0);
> +}
> 

So to make sure I understand....

Suppose I want to do a bind mount with the new API. Would I do something
like this?

    mfd = fsopen("???");
    write(mfd, "s /path/to/old/mount");
    write(mfd, "o bind");
    fsmount(mfd, ...);

That seems a bit klunkier than before as I now need to pay attention to
the fstype. I guess I'd have to scrape /proc/mounts for that info?
-- 
Jeff Layton <jlayton@redhat.com>

  reply	other threads:[~2017-10-26 17:21 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-06 15:49 [PATCH 00/14] VFS: Introduce filesystem context [ver #6] David Howells
2017-10-06 15:49 ` [PATCH 01/14] VFS: Introduce the structs and doc for a " David Howells
2017-10-06 15:49 ` [PATCH 02/14] VFS: Add LSM hooks for " David Howells
2017-10-06 20:37   ` Randy Dunlap
2017-10-06 15:49 ` [PATCH 03/14] VFS: Implement a filesystem superblock creation/configuration " David Howells
2017-10-06 20:34   ` Randy Dunlap
2017-10-06 23:13   ` David Howells
2017-10-07  0:08     ` Randy Dunlap
2017-10-10  7:49   ` Miklos Szeredi
2017-10-10 15:24   ` David Howells
2017-10-26 16:24   ` David Howells
2017-10-27  9:24     ` Miklos Szeredi
2017-10-27 14:35     ` David Howells
2017-10-27 15:33       ` Miklos Szeredi
2017-10-27 16:03       ` David Howells
2017-10-30  8:44         ` Miklos Szeredi
2017-10-06 15:49 ` [PATCH 04/14] VFS: Remove unused code after filesystem context changes " David Howells
2017-10-06 15:49 ` [PATCH 05/14] VFS: Implement fsopen() to prepare for a mount " David Howells
2017-10-26 17:11   ` Jeff Layton
2017-10-26 19:01   ` Jeff Layton
2017-10-06 15:49 ` [PATCH 06/14] VFS: Implement fsmount() to effect a pre-configured " David Howells
2017-10-10  8:00   ` Miklos Szeredi
2017-10-10  9:51     ` Karel Zak
2017-10-10 13:38       ` Miklos Szeredi
2017-10-11  8:54         ` Karel Zak
2017-10-06 15:50 ` [PATCH 07/14] VFS: Add a sample program for fsopen/fsmount " David Howells
2017-10-26 17:21   ` Jeff Layton [this message]
2017-10-26 22:40   ` David Howells
2017-10-06 15:50 ` [PATCH 08/14] procfs: Move proc_fill_super() to fs/proc/root.c " David Howells
2017-10-06 15:50 ` [PATCH 09/14] proc: Add fs_context support to procfs " David Howells
2017-10-06 15:50 ` [PATCH 10/14] ipc: Convert mqueue fs to fs_context " David Howells
2017-10-06 15:50 ` [PATCH 11/14] cpuset: Use " David Howells
2017-10-06 15:50 ` [PATCH 12/14] kernfs, sysfs, cgroup, intel_rdt: Support " David Howells
2017-10-06 15:50 ` [PATCH 13/14] hugetlbfs: Convert to " David Howells
2017-10-06 15:50 ` [PATCH 14/14] VFS: Remove kern_mount_data() " David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1509038513.29077.31.camel@redhat.com \
    --to=jlayton@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=mszeredi@redhat.com \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).