1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * NFS export of Lustre Light File System
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_LLITE
25 #include <linux/lustre_lite.h>
26 #include "llite_internal.h"
28 __u32 get_uuid2int(const char *name, int len)
30 __u32 key0 = 0x12a3fe2d, key1 = 0x37abe8f9;
32 __u32 key = key1 + (key0 ^ (*name++ * 7152373));
33 if (key & 0x80000000) key -= 0x7fffffff;
40 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
41 static int ll_nfs_test_inode(struct inode *inode, unsigned long ino,
44 static int ll_nfs_test_inode(struct inode *inode, void *opaque)
47 struct lustre_id *iid = opaque;
49 if (inode->i_ino == id_ino(iid) &&
50 inode->i_generation == id_gen(iid))
55 static struct inode * search_inode_for_lustre(struct super_block *sb,
57 unsigned long generation,
60 struct ptlrpc_request *req = NULL;
61 struct ll_sb_info *sbi = ll_s2sbi(sb);
64 int eadatalen = 0, rc;
65 struct inode *inode = NULL;
68 id_ino(&iid) = (__u64)ino;
69 id_gen(&iid) = generation;
70 inode = ILOOKUP(sb, ino, ll_nfs_test_inode, &iid);
75 eadatalen = obd_size_diskmd(sbi->ll_dt_exp, NULL);
76 valid |= OBD_MD_FLEASIZE;
79 id_ino(&id) = (__u64)ino;
80 id_gen(&id) = generation;
82 rc = md_getattr(sbi->ll_md_exp, &id, valid, NULL, 0,
85 CERROR("failure %d inode %lu\n", rc, ino);
89 rc = ll_prep_inode(sbi->ll_dt_exp, sbi->ll_md_exp,
92 ptlrpc_req_finished(req);
95 ptlrpc_req_finished(req);
100 extern struct dentry_operations ll_d_ops;
102 static struct dentry *ll_iget_for_nfs(struct super_block *sb, unsigned long ino,
103 __u32 generation, umode_t mode)
106 struct dentry *result;
107 struct list_head *lp;
110 return ERR_PTR(-ESTALE);
112 inode = search_inode_for_lustre(sb, ino, generation, mode);
114 return ERR_PTR(PTR_ERR(inode));
116 if (is_bad_inode(inode) ||
117 (generation && inode->i_generation != generation)){
118 /* we didn't find the right inode.. */
119 CERROR(" Inode %lu, Bad count: %lu %d or version %u %u\n",
120 inode->i_ino, (unsigned long)inode->i_nlink,
121 atomic_read(&inode->i_count), inode->i_generation,
124 return ERR_PTR(-ESTALE);
127 /* now to find a dentry.
128 * If possible, get a well-connected one
130 spin_lock(&dcache_lock);
131 for (lp = inode->i_dentry.next; lp != &inode->i_dentry ; lp=lp->next) {
132 result = list_entry(lp,struct dentry, d_alias);
133 if (!(result->d_flags & DCACHE_DISCONNECTED)) {
135 ll_set_dflags(result, DCACHE_REFERENCED);
136 spin_unlock(&dcache_lock);
141 spin_unlock(&dcache_lock);
142 result = d_alloc_root(inode);
143 if (result == NULL) {
145 return ERR_PTR(-ENOMEM);
147 result->d_flags |= DCACHE_DISCONNECTED;
150 result->d_op = &ll_d_ops;
154 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
155 int fhtype, int parent)
162 return ll_iget_for_nfs(sb, data[3], 0, data[4]);
168 return ll_iget_for_nfs(sb, data[0], data[1], data[2]);
171 return ERR_PTR(-EINVAL);
174 int ll_dentry_to_fh(struct dentry *dentry, __u32 *datap, int *lenp,
179 *datap++ = dentry->d_inode->i_ino;
180 *datap++ = dentry->d_inode->i_generation;
181 *datap++ = (__u32)(S_IFMT & dentry->d_inode->i_mode);
183 if (*lenp == 3 || S_ISDIR(dentry->d_inode->i_mode)) {
187 if (dentry->d_parent) {
188 *datap++ = dentry->d_parent->d_inode->i_ino;
189 *datap++ = (__u32)(S_IFMT & dentry->d_parent->d_inode->i_mode);