aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd/nfs4recover.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@cse.unsw.edu.au>2005-06-24 01:03:52 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-24 03:06:33 -0400
commita55370a3c0106106a975c5a09cee800611d0cf50 (patch)
tree408d5dc0ecf970c103ef091388e66da267adb2e2 /fs/nfsd/nfs4recover.c
parent7dea9d280c96f90382ec5d5709433e66a0993ec9 (diff)
[PATCH] knfsd: nfsd4: reboot hash
For the purposes of reboot recovery we keep a directory with subdirectories each having a name that is the ascii hex representation of the md5 sum of a client identifier for an active client. This adds the code to calculate that name. We also use it for the purposes of comparing clients, so if someone ever manages to find two client names that are md5 collisions, then we'll return clid_inuse to the second. Signed-off-by: Andy Adamson <andros@citi.umich.edu> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu> Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/nfsd/nfs4recover.c')
-rw-r--r--fs/nfsd/nfs4recover.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
new file mode 100644
index 000000000000..841a305d7948
--- /dev/null
+++ b/fs/nfsd/nfs4recover.c
@@ -0,0 +1,97 @@
1/*
2* linux/fs/nfsd/nfs4recover.c
3*
4* Copyright (c) 2004 The Regents of the University of Michigan.
5* All rights reserved.
6*
7* Andy Adamson <andros@citi.umich.edu>
8*
9* Redistribution and use in source and binary forms, with or without
10* modification, are permitted provided that the following conditions
11* are met:
12*
13* 1. Redistributions of source code must retain the above copyright
14* notice, this list of conditions and the following disclaimer.
15* 2. Redistributions in binary form must reproduce the above copyright
16* notice, this list of conditions and the following disclaimer in the
17* documentation and/or other materials provided with the distribution.
18* 3. Neither the name of the University nor the names of its
19* contributors may be used to endorse or promote products derived
20* from this software without specific prior written permission.
21*
22* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
23* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*
34*/
35
36
37#include <linux/sunrpc/svc.h>
38#include <linux/nfsd/nfsd.h>
39#include <linux/nfs4.h>
40#include <linux/nfsd/state.h>
41#include <linux/nfsd/xdr4.h>
42#include <asm/uaccess.h>
43#include <asm/scatterlist.h>
44#include <linux/crypto.h>
45
46
47#define NFSDDBG_FACILITY NFSDDBG_PROC
48
49static void
50md5_to_hex(char *out, char *md5)
51{
52 int i;
53
54 for (i=0; i<16; i++) {
55 unsigned char c = md5[i];
56
57 *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
58 *out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
59 }
60 *out = '\0';
61}
62
63int
64nfs4_make_rec_clidname(char *dname, struct xdr_netobj *clname)
65{
66 struct xdr_netobj cksum;
67 struct crypto_tfm *tfm;
68 struct scatterlist sg[1];
69 int status = nfserr_resource;
70
71 dprintk("NFSD: nfs4_make_rec_clidname for %.*s\n",
72 clname->len, clname->data);
73 tfm = crypto_alloc_tfm("md5", 0);
74 if (tfm == NULL)
75 goto out;
76 cksum.len = crypto_tfm_alg_digestsize(tfm);
77 cksum.data = kmalloc(cksum.len, GFP_KERNEL);
78 if (cksum.data == NULL)
79 goto out;
80 crypto_digest_init(tfm);
81
82 sg[0].page = virt_to_page(clname->data);
83 sg[0].offset = offset_in_page(clname->data);
84 sg[0].length = clname->len;
85
86 crypto_digest_update(tfm, sg, 1);
87 crypto_digest_final(tfm, cksum.data);
88
89 md5_to_hex(dname, cksum.data);
90
91 kfree(cksum.data);
92 status = nfs_ok;
93out:
94 if (tfm)
95 crypto_free_tfm(tfm);
96 return status;
97}