All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: torvalds@osdl.org, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-afs@lists.infradead.org,
	linux-fsdevel@vger.kernel.org, Wang Lei <wang840925@gmail.com>,
	David Howells <dhowells@redhat.com>
Subject: [PATCH 10/17] AFS: Implement the PWhereIs pioctl
Date: Tue, 16 Jun 2009 21:39:37 +0100	[thread overview]
Message-ID: <20090616203937.4526.53619.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20090616203845.4526.60013.stgit@warthog.procyon.org.uk>

From: Wang Lei <wang840925@gmail.com>

Implement the PWhereIs pioctl for AFS.  This will find out on which servers the
volume containing the specified file is located and return the IPv4 addresses
to userspace.

This can be tested with the OpenAFS userspace tools by doing:

	fs whereis /afs

on a mounted AFS filesystem, which should return something like:

	File /afs is on host altair.cambridge.redhat.com

Signed-off-by: Wang Lei <wang840925@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/afs/pioctl.c         |   51 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/afscall.h |    3 +++
 include/linux/venus.h   |    1 +
 3 files changed, 55 insertions(+), 0 deletions(-)


diff --git a/fs/afs/pioctl.c b/fs/afs/pioctl.c
index 4efd825..5f6beeb 100644
--- a/fs/afs/pioctl.c
+++ b/fs/afs/pioctl.c
@@ -97,6 +97,53 @@ long afs_PGetVolStat(struct dentry *dentry, struct vice_ioctl *arg,
 }
 
 /*
+ * Find out where a volume is located
+ */
+long afs_PWhereIs(struct dentry *dentry, struct vice_ioctl *arg,
+		  struct key *key)
+{
+	int i;
+	char *cp = arg->out;
+	const size_t addr_size = sizeof(struct in_addr);
+	struct afs_volume *volume = AFS_FS_I(dentry->d_inode)->volume;
+	long ret;
+
+	_enter("");
+
+	if (arg->out_size < AFS_MAXHOSTS * addr_size) {
+		_leave(" = -EINVAL [%d < %zu]", arg->out_size,
+		       AFS_MAXHOSTS * addr_size);
+		return -EINVAL;
+	}
+
+	down_read(&volume->server_sem);
+
+	/* handle the no-server case */
+	if (volume->nservers == 0) {
+		ret = volume->rjservers ? -ENOMEDIUM : -ESTALE;
+		up_read(&volume->server_sem);
+		_leave(" = %ld [no servers]", ret);
+		return ret;
+	}
+
+	for (i = 0; i < volume->nservers; i++, cp += addr_size)
+		memcpy(cp, &volume->servers[i]->addr.s_addr, addr_size);
+
+	up_read(&volume->server_sem);
+
+	if (i < AFS_MAXHOSTS) {
+		/* still room for terminating NULL, add it on the end */
+		memset(cp, 0, addr_size);
+		cp += addr_size;
+	}
+
+	arg->out_size = cp - arg->out;
+
+	_leave(" = 0 [%d]", arg->out_size);
+	return 0;
+}
+
+/*
  * The AFS path-based I/O control operation
  */
 long afs_pioctl(struct dentry *dentry, int cmd, struct vice_ioctl *arg)
@@ -130,6 +177,10 @@ long afs_pioctl(struct dentry *dentry, int cmd, struct vice_ioctl *arg)
 		ret = afs_PGetVolStat(dentry, arg, key);
 		break;
 
+	case VIOC_COMMAND(PWhereIs):
+		ret = afs_PWhereIs(dentry, arg, key);
+		break;
+
 	default:
 		_debug("fallback to pathless: %x", cmd);
 		ret = afs_pathless_pioctl(cmd, arg);
diff --git a/include/linux/afscall.h b/include/linux/afscall.h
index 6772712..0a60cd1 100644
--- a/include/linux/afscall.h
+++ b/include/linux/afscall.h
@@ -15,9 +15,12 @@
 
 /* pioctl commands */
 #define PGetVolStat	4		/* get volume status */
+#define PWhereIs	14		/* find out where a volume is located */
 #define PGetFID		22		/* get file ID */
 #define PGetFileCell	30		/* get the cell a file inhabits */
 
+#define AFS_MAXHOSTS	8		/* the maximum of hosts number */
+
 /*
  * AFS volume status record
  */
diff --git a/include/linux/venus.h b/include/linux/venus.h
index 437e7f3..78cbf47 100644
--- a/include/linux/venus.h
+++ b/include/linux/venus.h
@@ -18,6 +18,7 @@
  * pioctl commands (not usable as ioctls)
  */
 #define VIOCGETVOLSTAT		_VICEIOCTL(PGetVolStat)
+#define VIOCWHEREIS		_VICEIOCTL(PWhereIs)
 #define VIOCGETFID		_VICEIOCTL(PGetFID)
 #define VIOC_FILE_CELL_NAME	_VICEIOCTL(PGetFileCell)
 


  parent reply	other threads:[~2009-06-16 20:41 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-16 20:38 [PATCH 00/17] [RFC] AFS: Implement OpenAFS pioctls(version)s David Howells
2009-06-16 20:38 ` [PATCH 01/17] VFS: Implement the pioctl() system call David Howells
2009-06-16 20:54   ` Christoph Hellwig
2009-06-17  0:19   ` David Howells
2009-06-17  9:02     ` Alan Cox
2009-06-16 20:38 ` [PATCH 02/17] VFS: Implement the AFS " David Howells
2009-06-16 20:39 ` [PATCH 03/17] VFS: Implement handling for pathless pioctls David Howells
2009-06-17  7:47   ` Andreas Dilger
2009-06-17 18:26   ` David Howells
2009-06-16 20:39 ` [PATCH 04/17] AFS: Add key request for pioctl David Howells
2009-06-16 20:39 ` [PATCH 05/17] AFS: Handle pathless pioctls aimed at AFS David Howells
2009-06-16 20:39 ` [PATCH 06/17] VFS: Define pioctl command wrappers David Howells
2009-06-16 20:39 ` [PATCH 07/17] AFS: Implement the PGetFid pioctl David Howells
2009-06-16 20:39 ` [PATCH 08/17] AFS: Implement the PGetFileCell pioctl David Howells
2009-06-16 20:39 ` [PATCH 09/17] AFS: Implement the PGetVolStat pioctl David Howells
2009-06-16 20:39 ` David Howells [this message]
2009-06-17  7:51   ` [PATCH 10/17] AFS: Implement the PWhereIs pioctl Andreas Dilger
2009-06-17 18:05   ` David Howells
2009-06-16 20:39 ` [PATCH 11/17] AFS: Implement the PFlushCB pioctl David Howells
2009-06-16 20:39 ` [PATCH 12/17] KEYS: Export lookup_user_key() and the key permission request flags David Howells
2009-06-16 20:39 ` [PATCH 13/17] RxRPC: Record extra data in key David Howells
2009-06-16 20:39 ` [PATCH 14/17] RxRPC: Declare the security index constants symbolically David Howells
2009-06-16 20:40 ` [PATCH 15/17] AFS: Implement the PSetTokens pioctl David Howells
2009-06-16 20:40 ` [PATCH 16/17] KEYS: Add a function by which the contents of a keyring can be enumerated David Howells
2009-06-16 20:40 ` [PATCH 17/17] AFS: Implement the PGetTokens pioctl David Howells
2009-06-16 22:59 ` [PATCH 00/17] [RFC] AFS: Implement OpenAFS pioctls(version)s David Howells
2009-06-16 23:11   ` Alan Cox
2009-06-17  0:25   ` David Howells
2009-06-17  7:55     ` Andreas Dilger
2009-06-17 16:09       ` Linus Torvalds
2009-06-17 18:37         ` Al Viro
2009-06-17 18:44           ` Linus Torvalds
2009-06-17 18:52             ` Al Viro
2009-06-17 19:28             ` David Howells
2009-06-18 12:50               ` Olivier Galibert
2009-06-17 17:24       ` David Howells
2009-06-17 17:33         ` Linus Torvalds
2009-06-17 18:03         ` David Howells
2009-06-17 18:24           ` Linus Torvalds
2009-06-17 18:30           ` Theodore Tso
2009-06-17 19:14             ` david
2009-06-17 19:30             ` David Howells
2009-06-17 19:51           ` David Howells
2009-06-17 20:09             ` Linus Torvalds
2009-06-17  9:00     ` Alan Cox

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=20090616203937.4526.53619.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    --cc=wang840925@gmail.com \
    /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.