Subject: afs/fs/afs key_afs.c,NONE,1.1 volume.h,1.8,1.9 vnode.h,1.7,1.8 vnode.c,1.10,1.11 vlocation.c,1.13,1.14 super.c,1.10,1.11 main.c,1.13,1.14 kafstimod.c,1.8,1.9 kafsasyncd.c,1.7,1.8 internal.h,1.18,1.19 inode.c,1.13,1.14 file.c,1.10,1.11 dir.c,1.11,1.12 cmservice.c,1.9,1.10 cell.c,1.12,1.13 callback.c,1.4,1.5 cache.h,1.15,1.16 Makefile,1.12,1.13

From: [email-masked]
Date: Wed, 10 Sep 2003 09:23:18 +0100

Update of /home/cvs/afs/fs/afs
In directory phoenix.infradead.org:/tmp/cvs-serv18454/fs/afs

Modified Files:
	volume.h vnode.h vnode.c vlocation.c super.c main.c 
	kafstimod.c kafsasyncd.c internal.h inode.c file.c dir.c 
	cmservice.c cell.c callback.c cache.h Makefile 
Added Files:
	key_afs.c 
Log Message:
port to -test5
addition of autorisation key stuff

--- NEW FILE key_afs.c ---
/* key_afs.c: AFS filesystem keys
 *
 * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells ([email-masked])
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/key.h>
#include <linux/seq_file.h>
#include <asm/errno.h>
#include "cell.h"
#include "internal.h"

static int afs_key_init(struct key *key, const char *desc,
			size_t datalen, const char *data);
static int afs_key_match(const struct key *key, const void *desc);
static void afs_key_clear(struct key *key);
static void afs_key_describe(const struct key *keyring, struct seq_file *m);

struct afs_key_data {
	uint16_t	session_key_size;
	uint16_t	ticket_size;
	int32_t		kvno;
	time_t		expiry;
	uint8_t		data[0];
};

/* AFS Kerberos ticket
 * - the description must be the name of the cell to which applicable
 * - the data is a struct afs_key_data
 */
struct key_type key_type_afs = {
	.name		= "afs",
	.link		= LIST_HEAD_INIT(key_type_afs.link),
	.init		= afs_key_init,
	.match		= afs_key_match,
	.clear		= afs_key_clear,
	.describe	= afs_key_describe,
};

static int afs_key_init(struct key *key, const char *desc,
			size_t datalen, const char *data)
{
	struct afs_key_data *keydata = (void *) data;
	size_t dlen;

	kenter("{%u},%s,%zu,{sk=%hu,tkt=%hu,v=%d,xp=%x}",
	       key->serial, desc, datalen,
	       keydata->session_key_size,
	       keydata->ticket_size,
	       keydata->kvno,
	       (int) keydata->expiry);

	dlen = strlen(desc) + 1;
	key->description.data = kmalloc(dlen, GFP_KERNEL);
	if (!key->description.data) {
		kleave(" = -ENOMEM");
		return -ENOMEM;
	}
	memcpy(key->description.data, desc, dlen);

	key->payload.data = kmalloc(datalen, GFP_KERNEL);
	if (!key->payload.data) {
		kleave(" = -ENOMEM");
		return -ENOMEM;
	}

	key->datalen = datalen;
	memcpy(key->payload.data, data, datalen);

	kleave(" = 0");
	return 0;
}

static int afs_key_match(const struct key *key, const void *desc)
{
	if (!key->description.data)
		return 0;

	return strcmp(key->description.data, desc) == 0 ? 1 : 0;
}

static void afs_key_clear(struct key *key)
{
	if (key->description.data)
		kfree(key->description.data);
	if (key->payload.data)
		kfree(key->payload.data);
}

static void afs_key_describe(const struct key *key, struct seq_file *m)
{
	struct afs_key_data *keydata;

	if (!key->description.data) {
		seq_puts(m, "[anon]");
		return;
	}

	keydata = key->payload.data;

	seq_printf(m, "%s => { s=%hu t=%hu v=%d x=%x }",
		   (char *) key->description.data,
		   keydata->session_key_size,
		   keydata->ticket_size,
		   keydata->kvno,
		   (int) keydata->expiry);
}

int __init afs_key_register(void)
{
	return register_key_type(&key_type_afs);
}

void __exit afs_key_unregister(void)
{
	unregister_key_type(&key_type_afs);
}

Index: volume.h
===================================================================
RCS file: /home/cvs/afs/fs/afs/volume.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- volume.h	19 Aug 2003 13:37:08 -0000	1.8
+++ volume.h	10 Sep 2003 08:23:15 -0000	1.9
@@ -133,7 +133,8 @@
 
 extern void afs_put_volume(struct afs_volume *volume);
 
-extern int afs_volume_pick_fileserver(struct afs_volume *volume, struct afs_server **_server);
+extern int afs_volume_pick_fileserver(struct afs_volume *volume,
+				      struct afs_server **_server);
 
 extern int afs_volume_release_fileserver(struct afs_volume *volume,
 					 struct afs_server *server,

Index: vnode.h
===================================================================
RCS file: /home/cvs/afs/fs/afs/vnode.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- vnode.h	19 Aug 2003 13:37:08 -0000	1.7
+++ vnode.h	10 Sep 2003 08:23:15 -0000	1.8
@@ -13,7 +13,6 @@
 #define _LINUX_AFS_VNODE_H
 
 #include <linux/fs.h>
-#include <linux/version.h>
 #include "server.h"
 #include "kafstimod.h"
 #include "cache.h"

Index: vnode.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/vnode.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- vnode.c	19 Aug 2003 13:37:08 -0000	1.10
+++ vnode.c	10 Sep 2003 08:23:15 -0000	1.11
@@ -21,7 +21,6 @@
 #include "fsclient.h"
 #include "vlclient.h"
 #include "vnode.h"
-#include "cache.h"
 #include "internal.h"
 
 static void afs_vnode_cb_timed_out(struct afs_timer *timer);

Index: vlocation.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/vlocation.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- vlocation.c	19 Aug 2003 13:37:08 -0000	1.13
+++ vlocation.c	10 Sep 2003 08:23:15 -0000	1.14
@@ -21,7 +21,6 @@
 #include "fsclient.h"
 #include "vlclient.h"
 #include "kafstimod.h"
-#include "cache.h"
 #include <rxrpc/connection.h>
 #include "internal.h"

Index: super.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/super.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- super.c	15 Aug 2003 13:02:20 -0000	1.10
+++ super.c	10 Sep 2003 08:23:15 -0000	1.11
@@ -83,7 +83,7 @@
 {
 	int ret;
 
-	kenter("");
+	_enter("");
 
 #ifdef AFS_AUTOMOUNT_SUPPORT
 	afs_timer_init(&afs_mntpt_expiry_timer, &afs_mntpt_expiry_timer_ops);
@@ -313,14 +313,14 @@
 	struct super_block *sb;
 	int ret;
 
-	kenter(",,%s,%p", dev_name, options);
+	_enter(",,%s,%p", dev_name, options);
 
 	memset(&params, 0, sizeof(params));
 
 	/* start the cache manager */
 	ret = afscm_start();
 	if (ret < 0) {
-		kleave(" = %d", ret);
+		_leave(" = %d", ret);
 		return ERR_PTR(ret);
 	}
 
@@ -345,12 +345,6 @@
 		goto error;
 
 	/* allocate a deviceless superblock */
-#if 0
-	sb = get_sb_nodev(fs_type, flags, &params, afs_fill_super);
-	if (IS_ERR(sb))
-		afscm_stop();
-
-#else
 	sb = sget(fs_type, afs_test_super, set_anon_super, &params);
 	if (IS_ERR(sb))
 		goto error;
@@ -365,18 +359,16 @@
 	}
 	sb->s_flags |= MS_ACTIVE;
 
-#endif
-
 	afs_put_volume(params.volume);
 	afs_put_cell(params.default_cell);
-	kleave(" = %p", sb);
+	_leave(" = %p", sb);
 	return sb;
 
  error:
 	afs_put_volume(params.volume);
 	afs_put_cell(params.default_cell);
 	afscm_stop();
-	kleave(" = %d", ret);
+	_leave(" = %d", ret);
 	return ERR_PTR(ret);
 } /* end afs_get_sb() */

Index: main.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/main.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- main.c	15 Aug 2003 14:16:56 -0000	1.13
+++ main.c	10 Sep 2003 08:23:15 -0000	1.14
@@ -77,41 +77,47 @@
 
 	/* register the /proc stuff */
 	ret = afs_proc_init();
-	if (ret<0)
+	if (ret < 0)
 		return ret;
 
 #ifdef AFS_CACHING_SUPPORT
 	/* we want to be able to cache */
 	ret = cachefs_register_netfs(&afs_cache_netfs,&afs_cache_cell_index_def);
-	if (ret<0)
+	if (ret < 0)
 		goto error;
 #endif
 
+#ifdef CONFIG_KEYS
+	ret = afs_key_register();
+	if (ret < 0)
+		goto error_cache;
+#endif
+
 	/* initialise the cell DB */
 	ret = afs_cell_init();
-	if (ret<0)
-		goto error_cache;
+	if (ret < 0)
+		goto error_keys;
 
 	/* start the timeout daemon */
 	ret = afs_kafstimod_start();
-	if (ret<0)
-		goto error;
+	if (ret < 0)
+		goto error_keys;
 
 	/* start the async operation daemon */
 	ret = afs_kafsasyncd_start();
-	if (ret<0)
+	if (ret < 0)
 		goto error_kafstimod;
 
 	/* create the RxRPC transport */
 	ret = rxrpc_create_transport(7001,&afs_transport);
-	if (ret<0)
+	if (ret < 0)
 		goto error_kafsasyncd;
 
 	afs_transport->peer_ops = &afs_peer_ops;
 
 	/* register the filesystems */
 	ret = afs_fs_init();
-	if (ret<0)
+	if (ret < 0)
 		goto error_transport;
 
 	return ret;
@@ -122,11 +128,15 @@
 	afs_kafsasyncd_stop();
  error_kafstimod:
 	afs_kafstimod_stop();
+ error_keys:
+#ifdef CONFIG_KEYS
+	afs_key_unregister();
  error_cache:
+#endif
 #ifdef AFS_CACHING_SUPPORT
 	cachefs_unregister_netfs(&afs_cache_netfs);
-#endif
  error:
+#endif
 	afs_cell_purge();
 	afs_proc_cleanup();
 	printk(KERN_ERR "kAFS: failed to register: %d\n",ret);
@@ -146,6 +156,9 @@
 	afs_kafstimod_stop();
 	afs_kafsasyncd_stop();
 	afs_cell_purge();
+#ifdef CONFIG_KEYS
+	afs_key_unregister();
+#endif
 #ifdef AFS_CACHING_SUPPORT
 	cachefs_unregister_netfs(&afs_cache_netfs);
 #endif
@@ -169,7 +182,7 @@
 
 	/* determine which server the peer resides in (if any) */
 	ret = afs_server_find_by_peer(peer,&server);
-	if (ret<0)
+	if (ret < 0)
 		return ret; /* none that we recognise, so abort */
 
 	_debug("Server %p{u=%d}\n",server,atomic_read(&server->usage));

Index: kafstimod.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/kafstimod.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- kafstimod.c	3 Sep 2003 12:44:20 -0000	1.8
+++ kafstimod.c	10 Sep 2003 08:23:15 -0000	1.9
@@ -9,7 +9,6 @@
  * 2 of the License, or (at your option) any later version.
  */
 
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/sched.h>

Index: kafsasyncd.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/kafsasyncd.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- kafsasyncd.c	3 Sep 2003 12:44:20 -0000	1.7
+++ kafsasyncd.c	10 Sep 2003 08:23:15 -0000	1.8
@@ -16,7 +16,6 @@
  * - poll volume location servers to keep up to date volume location lists
  */
 
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/sched.h>

Index: internal.h
===================================================================
RCS file: /home/cvs/afs/fs/afs/internal.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- internal.h	19 Aug 2003 13:37:08 -0000	1.18
+++ internal.h	10 Sep 2003 08:23:15 -0000	1.19
@@ -12,7 +12,6 @@
 #ifndef AFS_INTERNAL_H
 #define AFS_INTERNAL_H
 
-#include <linux/version.h>
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/fs.h>
@@ -84,6 +83,14 @@
 extern int afs_iget(struct super_block *sb, afs_fid_t *fid, struct inode **_inode);
 extern int afs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
 extern void afs_clear_inode(struct inode *inode);
+
+/*
+ * key_afs.c
+ */
+#ifdef CONFIG_KEYS
+extern int afs_key_register(void);
+extern void afs_key_unregister(void);
+#endif
 
 /*
  * main.c

Index: inode.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/inode.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- inode.c	19 Aug 2003 13:37:08 -0000	1.13
+++ inode.c	10 Sep 2003 08:23:15 -0000	1.14
@@ -23,7 +23,6 @@
 #include "volume.h"
 #include "vnode.h"
 #include "super.h"
-#include "cache.h"
 #include "internal.h"
 
 struct afs_iget_data {
@@ -69,7 +68,6 @@
 	inode->i_nlink		= vnode->status.nlink;
 	inode->i_uid		= vnode->status.owner;
 	inode->i_gid		= 0;
-	inode->i_rdev		= NODEV;
 	inode->i_size		= vnode->status.size;
 	inode->i_ctime.tv_sec	= vnode->status.mtime_server;
 	inode->i_ctime.tv_nsec	= 0;

Index: file.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/file.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- file.c	19 Aug 2003 13:37:08 -0000	1.10
+++ file.c	10 Sep 2003 08:23:16 -0000	1.11
@@ -19,7 +19,6 @@
 #include <linux/buffer_head.h>
 #include "volume.h"
 #include "vnode.h"
-#include "cache.h"
 #include <rxrpc/call.h>
 #include "internal.h"

Index: dir.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/dir.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- dir.c	18 Jul 2003 15:25:53 -0000	1.11
+++ dir.c	10 Sep 2003 08:23:16 -0000	1.12
@@ -573,7 +573,7 @@
 			spin_lock(&AFS_FS_I(inode)->lock);
 			AFS_FS_I(inode)->flags |= AFS_VNODE_DELETED;
 			spin_unlock(&AFS_FS_I(inode)->lock);
-			invalidate_inode_pages(inode->i_mapping);
+			invalidate_remote_inode(inode);
 			goto out_bad;
 		}

Index: cmservice.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/cmservice.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- cmservice.c	3 Sep 2003 12:44:20 -0000	1.9
+++ cmservice.c	10 Sep 2003 08:23:16 -0000	1.10
@@ -9,7 +9,6 @@
  * 2 of the License, or (at your option) any later version.
  */
 
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/sched.h>

Index: cell.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/cell.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- cell.c	19 Aug 2003 13:37:08 -0000	1.12
+++ cell.c	10 Sep 2003 08:23:16 -0000	1.13
@@ -21,7 +21,6 @@
 #include "vlclient.h"
 #include "kafstimod.h"
 #include "super.h"
-#include "cache.h"
 #include "internal.h"
 
 DECLARE_RWSEM(afs_proc_cells_sem);

Index: callback.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/callback.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- callback.c	4 Jul 2003 15:26:31 -0000	1.4
+++ callback.c	10 Sep 2003 08:23:16 -0000	1.5
@@ -146,7 +146,7 @@
 			spin_unlock(&vnode->lock);
 
 			if (valid) {
-				invalidate_inode_pages(inode->i_mapping);
+				invalidate_remote_inode(inode);
 				afs_put_server(server);
 			}
 			iput(inode);

Index: cache.h
===================================================================
RCS file: /home/cvs/afs/fs/afs/cache.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- cache.h	19 Aug 2003 13:37:08 -0000	1.15
+++ cache.h	10 Sep 2003 08:23:16 -0000	1.16
@@ -14,7 +14,6 @@
 
 #define AFS_CACHING_SUPPORT
 
-#include <linux/version.h>
 #include <linux/mm.h>
 #ifdef AFS_CACHING_SUPPORT
 #include <linux/cachefs.h>

Index: Makefile
===================================================================
RCS file: /home/cvs/afs/fs/afs/Makefile,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Makefile	4 Jul 2003 15:26:31 -0000	1.12
+++ Makefile	10 Sep 2003 08:23:16 -0000	1.13
@@ -25,6 +25,8 @@
 	vnode.o \
 	volume.o
 
-obj-$(CONFIG_AFS_FS)  := kafs.o
+ifeq ($(CONFIG_KEYS),y)
+kafs-objs += key_afs.o
+endif
 
-#include $(TOPDIR)/Rules.make
+obj-$(CONFIG_AFS_FS)  := kafs.o