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;
45 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
46 static int ll_nfs_test_inode(struct inode *inode, unsigned long ino, void *opaque)
48 static int ll_nfs_test_inode(struct inode *inode, void *opaque)
51 struct lu_fid *ifid = &ll_i2info(inode)->lli_fid;
52 struct lu_fid *lfid = opaque;
54 if (memcmp(ifid, lfid, sizeof(struct lu_fid)) == 0)
60 static struct inode *search_inode_for_lustre(struct super_block *sb,
64 struct ll_sb_info *sbi = ll_s2sbi(sb);
65 struct ptlrpc_request *req = NULL;
66 struct inode *inode = NULL;
67 unsigned long valid = 0;
68 int eadatalen = 0, rc;
70 inode = ILOOKUP(sb, ll_fid_build_ino(sbi, fid),
71 ll_nfs_test_inode, fid);
76 rc = ll_get_max_mdsize(sbi, &eadatalen);
79 valid |= OBD_MD_FLEASIZE;
82 rc = md_getattr(sbi->ll_md_exp, fid, valid, eadatalen, &req);
84 CERROR("can't get object attrs, fid "DFID", rc %d\n",
89 rc = ll_prep_inode(&inode, req, REPLY_REC_OFF, sb);
91 ptlrpc_req_finished(req);
94 ptlrpc_req_finished(req);
99 extern struct dentry_operations ll_d_ops;
101 static struct dentry *ll_iget_for_nfs(struct super_block *sb,
102 struct lu_fid *fid, umode_t mode)
105 struct dentry *result;
106 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
107 struct list_head *lp;
110 if (!fid_is_sane(fid))
111 return ERR_PTR(-ESTALE);
113 inode = search_inode_for_lustre(sb, fid, mode);
115 return ERR_PTR(PTR_ERR(inode));
117 if (is_bad_inode(inode)) {
118 /* we didn't find the right inode.. */
119 CERROR("can't get inode by fid "DFID"\n",
122 return ERR_PTR(-ESTALE);
125 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
126 result = d_alloc_anon(inode);
129 return ERR_PTR(-ENOMEM);
132 /* now to find a dentry.
133 * If possible, get a well-connected one
135 spin_lock(&dcache_lock);
136 for (lp = inode->i_dentry.next; lp != &inode->i_dentry ; lp=lp->next) {
137 result = list_entry(lp,struct dentry, d_alias);
139 if (!(result->d_flags & DCACHE_DISCONNECTED)) {
141 ll_set_dflags(result, DCACHE_REFERENCED);
142 unlock_dentry(result);
143 spin_unlock(&dcache_lock);
147 unlock_dentry(result);
149 spin_unlock(&dcache_lock);
150 result = d_alloc_root(inode);
151 if (result == NULL) {
153 return ERR_PTR(-ENOMEM);
155 result->d_flags |= DCACHE_DISCONNECTED;
159 result->d_op = &ll_d_ops;
163 static void ll_fh_to_fid(struct lu_fid *fid, __u32 *mode, __u32 *datap)
165 /* unpacking ->f_seq */
166 fid->f_seq = datap[0];
167 fid->f_seq = (fid->f_seq << 32) | datap[1];
169 /* unpacking ->f_num */
170 fid->f_ver = datap[2];
171 fid->f_oid = datap[3];
176 static void ll_fid_to_fh(struct lu_fid *fid, __u32 *mode, __u32 *datap)
178 /* packing ->f_seq */
179 *datap++ = (__u32)(fid_seq(fid) >> 32);
180 *datap++ = (__u32)(fid_seq(fid) & 0x00000000ffffffff);
182 /* packing ->f_num */
183 *datap++ = fid_ver(fid);
184 *datap++ = fid_oid(fid);
186 /* packing inode mode */
187 *datap++ = (__u32)(S_IFMT & *mode);
190 struct dentry *ll_fh_to_dentry(struct super_block *sb, __u32 *data, int len,
191 int fhtype, int parent)
201 /* getting fid from parent's patr of @fh. That
203 ll_fh_to_fid(&fid, &mode, data + 5);
204 return ll_iget_for_nfs(sb, &fid, mode);
211 ll_fh_to_fid(&fid, &mode, data);
212 return ll_iget_for_nfs(sb, &fid, mode);
215 return ERR_PTR(-EINVAL);
218 int ll_dentry_to_fh(struct dentry *dentry, __u32 *datap, int *lenp,
221 struct inode *child = dentry->d_inode;
226 /* XXX: there is suspection that @datap is 5*4 bytes max long, so that
227 * 10*4 bytes (two fids + two times mode) does not fit into it. Not sure
228 * how to fix it though. */
229 ll_fid_to_fh(&ll_i2info(child)->lli_fid,
230 (__u32 *)&child->i_mode, datap);
232 if (*lenp == 5 || S_ISDIR(child->i_mode)) {
236 if (dentry->d_parent) {
237 struct inode *parent = dentry->d_parent->d_inode;
239 ll_fid_to_fh(&ll_i2info(parent)->lli_fid,
240 (__u32 *)&parent->i_mode, datap);
248 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
249 struct dentry *ll_get_dentry(struct super_block *sb, void *data)
251 __u32 *inump = (__u32*)data;
254 /* FIXME: seems this is not enough */
255 fid.f_seq = inump[0];
256 fid.f_oid = inump[1];
258 return ll_iget_for_nfs(sb, &fid, S_IFREG);
261 struct dentry *ll_get_parent(struct dentry *dchild)
263 struct ptlrpc_request *req = NULL;
264 struct inode *dir = dchild->d_inode;
265 struct ll_sb_info *sbi;
266 struct dentry *result = NULL;
267 struct mdt_body *body;
268 char dotdot[] = "..";
272 LASSERT(dir && S_ISDIR(dir->i_mode));
274 sbi = ll_s2sbi(dir->i_sb);
276 rc = md_getattr_name(sbi->ll_md_exp, ll_inode2fid(dir),
277 dotdot, strlen(dotdot) + 1,
280 CERROR("failure %d inode %lu get parent\n", rc, dir->i_ino);
283 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof (*body));
285 LASSERT((body->valid & OBD_MD_FLGENER) && (body->valid & OBD_MD_FLID));
287 result = ll_iget_for_nfs(dir->i_sb, ll_inode2fid(dir), S_IFDIR);
290 rc = PTR_ERR(result);
292 ptlrpc_req_finished(req);
298 struct export_operations lustre_export_operations = {
299 .get_parent = ll_get_parent,
300 .get_dentry = ll_get_dentry,