All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
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
Subject: [PATCH 13/23] VFS: Add a sample program for fsopen/fsmount [ver #4]
Date: Mon, 22 May 2017 16:53:31 +0100	[thread overview]
Message-ID: <149546841172.9289.17259162496296647409.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <149546825563.9289.9065118651584207610.stgit@warthog.procyon.org.uk>

Add a sample program for driving fsopen/fsmount.

Signed-off-by: David Howells <dhowells@redhat.com>
---

 samples/fsmount/test-fsmount.c |   92 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 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..30caad8e05a3
--- /dev/null
+++ b/samples/fsmount/test-fsmount.c
@@ -0,0 +1,92 @@
+/* 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 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;
+
+	if (prctl(PR_ERRMSG_ENABLE, 1) < 0) {
+		perror("prctl/en");
+		exit(1);
+	}
+
+	/* 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");
+	E_write(mfd, "x create");
+	if (fsmount(mfd, AT_FDCWD, "/mnt", 0, 0) < 0)
+		mount_error(mfd, "fsmount");
+	E(close(mfd));
+
+	exit(0);
+}

  parent reply	other threads:[~2017-05-22 15:53 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-22 15:50 [RFC][PATCH 00/23] VFS: Introduce superblock configuration context [ver #4] David Howells
2017-05-22 15:51 ` [PATCH 01/23] Provide a function to create a NUL-terminated string from unterminated data " David Howells
2017-05-22 15:51 ` [PATCH 02/23] VFS: Clean up whitespace in fs/namespace.c " David Howells
2017-05-22 15:51 ` [PATCH 03/23] VFS: Make get_mnt_ns() return the namespace " David Howells
2017-05-22 15:52 ` [PATCH 04/23] VFS: Make get_filesystem() return the affected filesystem " David Howells
2017-05-22 15:52 ` [PATCH 05/23] VFS: Provide empty name qstr " David Howells
2017-05-22 15:52 ` [PATCH 06/23] Provide supplementary error message facility " David Howells
2017-05-22 15:52 ` [PATCH 07/23] VFS: Introduce the structs and doc for a superblock configuration context " David Howells
2017-05-22 15:52 ` [PATCH 08/23] VFS: Add LSM hooks for " David Howells
2017-05-22 15:53 ` [PATCH 09/23] VFS: Implement a " David Howells
2017-05-22 15:53 ` [PATCH 10/23] VFS: Remove unused code after superblock config context changes " David Howells
2017-05-22 15:53 ` [PATCH 11/23] VFS: Implement fsopen() to prepare for a mount " David Howells
2017-05-22 15:53 ` [PATCH 12/23] VFS: Implement fsmount() to effect a pre-configured " David Howells
2017-05-22 15:53 ` David Howells [this message]
2017-05-22 15:53 ` [PATCH 14/23] procfs: Move proc_fill_super() to fs/proc/root.c " David Howells
2017-05-22 15:53 ` [PATCH 15/23] proc: Add superblock config support to procfs " David Howells
2017-05-22 15:53 ` [PATCH 16/23] NFS: Move sb-configuration bits into their own file " David Howells
2017-05-22 15:54 ` [PATCH 17/23] NFS: Constify mount argument match tables " David Howells
2017-05-22 15:54 ` [PATCH 18/23] NFS: Rename struct nfs_parsed_mount_data to struct nfs_sb_config " David Howells
2017-05-22 15:54 ` [PATCH 19/23] NFS: Split nfs_parse_mount_options() " David Howells
2017-05-22 15:54 ` [PATCH 20/23] NFS: Deindent nfs_sb_config_parse_option() " David Howells
2017-05-22 15:54 ` [PATCH 21/23] NFS: Add a small buffer in nfs_sb_config to avoid string dup " David Howells
2017-05-22 15:54 ` [PATCH 22/23] NFS: Do some tidying of the parsing code " David Howells
2017-05-22 15:54 ` [PATCH 23/23] NFS: Add sb_config support. " David Howells
2017-05-30 14:50 ` [RFC][PATCH 00/23] VFS: Introduce superblock configuration context " Al Viro
2017-05-30 14:50   ` Al Viro
2017-05-30 15:36 ` David Howells
2017-05-31  7:51   ` Miklos Szeredi
2017-06-02 10:14 ` David Howells
2017-06-09  7:48 ` Some filesystems set MNT_* flags in superblock->s_flags David Howells
2017-06-09  8:02   ` Miklos Szeredi

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=149546841172.9289.17259162496296647409.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=jlayton@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.