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 <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, void *opaque)
43 static int ll_nfs_test_inode(struct inode *inode, void *opaque)
46 struct ll_fid *iid = opaque;
48 if (inode->i_ino == iid->id && inode->i_generation == iid->generation)
54 static struct inode * search_inode_for_lustre(struct super_block *sb,
56 unsigned long generation,
59 struct ptlrpc_request *req = NULL;
60 struct ll_sb_info *sbi = ll_s2sbi(sb);
62 unsigned long valid = 0;
63 int eadatalen = 0, rc;
64 struct inode *inode = NULL;
65 struct ll_fid iid = { .id = ino, .generation = generation };
68 inode = ILOOKUP(sb, ino, ll_nfs_test_inode, &iid);
73 rc = ll_get_max_mdsize(sbi, &eadatalen);
76 valid |= OBD_MD_FLEASIZE;
79 fid.generation = generation;
82 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, eadatalen, &req);
84 CERROR("failure %d inode %lu\n", rc, ino);
88 rc = ll_prep_inode(sbi->ll_osc_exp, &inode, req, REPLY_REC_OFF, sb);
90 ptlrpc_req_finished(req);
93 ptlrpc_req_finished(req);
98 extern struct dentry_operations ll_d_ops;
100 static struct dentry *ll_iget_for_nfs(struct super_block *sb, unsigned long ino,
101 __u32 generation, umode_t mode)
104 struct dentry *result;
105 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
106 struct list_head *lp;
111 RETURN(ERR_PTR(-ESTALE));
113 inode = search_inode_for_lustre(sb, ino, generation, mode);
115 RETURN(ERR_PTR(PTR_ERR(inode)));
117 if (is_bad_inode(inode) ||
118 (generation && inode->i_generation != generation)){
119 /* we didn't find the right inode.. */
120 CERROR("Inode %lu, Bad count: %lu %d or version %u %u\n",
121 inode->i_ino, (unsigned long)inode->i_nlink,
122 atomic_read(&inode->i_count), inode->i_generation,
125 RETURN(ERR_PTR(-ESTALE));
128 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
129 result = d_alloc_anon(inode);
132 RETURN(ERR_PTR(-ENOMEM));
135 /* now to find a dentry.
136 * If possible, get a well-connected one
138 spin_lock(&dcache_lock);
139 for (lp = inode->i_dentry.next; lp != &inode->i_dentry ; lp=lp->next) {
140 result = list_entry(lp,struct dentry, d_alias);
142 if (!(result->d_flags & DCACHE_DISCONNECTED)) {
144 ll_set_dflags(result, DCACHE_REFERENCED);
145 unlock_dentry(result);
146 spin_unlock(&dcache_lock);
150 unlock_dentry(result);
152 spin_unlock(&dcache_lock);
153 result = d_alloc_root(inode);
154 if (result == NULL) {
156 RETURN(ERR_PTR(-ENOMEM));
158 result->d_flags |= DCACHE_DISCONNECTED;
162 result->d_op = &ll_d_ops;
166 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
167 int fhtype, int parent)
174 return ll_iget_for_nfs(sb, data[3], 0, data[4]);
180 return ll_iget_for_nfs(sb, data[0], data[1], data[2]);
183 return ERR_PTR(-EINVAL);
186 int ll_dentry_to_fh(struct dentry *dentry, __u32 *datap, int *lenp,
191 *datap++ = dentry->d_inode->i_ino;
192 *datap++ = dentry->d_inode->i_generation;
193 *datap++ = (__u32)(S_IFMT & dentry->d_inode->i_mode);
195 if (*lenp == 3 || S_ISDIR(dentry->d_inode->i_mode)) {
199 if (dentry->d_parent) {
200 *datap++ = dentry->d_parent->d_inode->i_ino;
201 *datap++ = (__u32)(S_IFMT & dentry->d_parent->d_inode->i_mode);
210 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
211 struct dentry *ll_get_dentry(struct super_block *sb, void *data)
213 __u32 *inump = (__u32*)data;
214 return ll_iget_for_nfs(sb, inump[0], inump[1], S_IFREG);
217 struct dentry *ll_get_parent(struct dentry *dchild)
219 struct ptlrpc_request *req = NULL;
220 struct inode *dir = dchild->d_inode;
221 struct ll_sb_info *sbi;
222 struct dentry *result = NULL;
224 struct mds_body *body;
225 char dotdot[] = "..";
229 LASSERT(dir && S_ISDIR(dir->i_mode));
231 sbi = ll_s2sbi(dir->i_sb);
233 fid.id = (__u64)dir->i_ino;
234 fid.generation = dir->i_generation;
235 fid.f_type = S_IFDIR;
237 rc = mdc_getattr_name(sbi->ll_mdc_exp, &fid, dotdot, strlen(dotdot) + 1,
240 CERROR("failure %d inode %lu get parent\n", rc, dir->i_ino);
243 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof (*body));
245 LASSERT((body->valid & OBD_MD_FLGENER) && (body->valid & OBD_MD_FLID));
247 result = ll_iget_for_nfs(dir->i_sb, body->ino, body->generation, S_IFDIR);
250 rc = PTR_ERR(result);
252 ptlrpc_req_finished(req);
258 struct export_operations lustre_export_operations = {
259 .get_parent = ll_get_parent,
260 .get_dentry = ll_get_dentry,