1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/sched.h>
25 #include <linux/smp_lock.h>
26 #include <linux/quotaops.h>
27 #include <linux/highmem.h>
28 #include <linux/pagemap.h>
30 #define DEBUG_SUBSYSTEM S_LLITE
32 #include <obd_support.h>
33 #include <lustre_lite.h>
34 #include <lustre_dlm.h>
35 #include <lustre_ver.h>
36 #include <lustre_mdc.h>
37 #include "llite_internal.h"
41 extern struct dentry_operations ll_d_ops;
43 int ll_unlock(__u32 mode, struct lustre_handle *lockh)
47 ldlm_lock_decref(lockh, mode);
52 /* Get an inode by inode number (already instantiated by the intent lookup).
53 * Returns inode or NULL
55 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
56 int ll_set_inode(struct inode *inode, void *opaque)
58 ll_read_inode2(inode, opaque);
62 struct inode *ll_iget(struct super_block *sb, ino_t hash,
65 struct ll_inode_info *lli;
69 inode = iget_locked(sb, hash);
71 if (inode->i_state & I_NEW) {
72 lli = ll_i2info(inode);
73 ll_read_inode2(inode, md);
74 unlock_new_inode(inode);
76 ll_update_inode(inode, md);
78 CDEBUG(D_VFSTRACE, "inode: %lu/%u(%p)\n",
79 inode->i_ino, inode->i_generation, inode);
85 struct inode *ll_iget(struct super_block *sb, ino_t hash,
91 inode = iget4(sb, hash, NULL, md);
93 if (!(inode->i_state & (I_FREEING | I_CLEAR)))
94 ll_update_inode(inode, md);
96 CDEBUG(D_VFSTRACE, "inode: %lu/%u(%p)\n",
97 inode->i_ino, inode->i_generation, inode);
103 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
104 void *data, int flag)
107 struct lustre_handle lockh;
111 case LDLM_CB_BLOCKING:
112 ldlm_lock2handle(lock, &lockh);
113 rc = ldlm_cli_cancel(&lockh);
115 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
119 case LDLM_CB_CANCELING: {
120 struct inode *inode = ll_inode_from_lock(lock);
121 __u64 bits = lock->l_policy_data.l_inodebits.bits;
123 /* Invalidate all dentries associated with this inode */
127 if (lock->l_resource->lr_name.name[0] != fid_seq(ll_inode2fid(inode)) ||
128 lock->l_resource->lr_name.name[1] != fid_oid(ll_inode2fid(inode)) ||
129 lock->l_resource->lr_name.name[2] != fid_ver(ll_inode2fid(inode))) {
130 LDLM_ERROR(lock, "data mismatch with object "DFID" (%p)",
131 PFID(ll_inode2fid(inode)), inode);
134 if (bits & MDS_INODELOCK_UPDATE)
135 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
136 &(ll_i2info(inode)->lli_flags));
139 if (S_ISDIR(inode->i_mode) &&
140 (bits & MDS_INODELOCK_UPDATE)) {
141 CDEBUG(D_INODE, "invalidating inode %lu\n",
143 truncate_inode_pages(inode->i_mapping, 0);
146 if (inode->i_sb->s_root &&
147 inode != inode->i_sb->s_root->d_inode &&
148 (bits & MDS_INODELOCK_LOOKUP))
149 ll_unhash_aliases(inode);
160 /* Pack the required supplementary groups into the supplied groups array.
161 * If we don't need to use the groups from the target inode(s) then we
162 * instead pack one or more groups from the user's supplementary group
163 * array in case it might be useful. Not needed if doing an MDS-side upcall. */
164 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
169 LASSERT(suppgids != NULL);
171 if (in_group_p(i1->i_gid))
172 suppgids[0] = i1->i_gid;
177 if (in_group_p(i2->i_gid))
178 suppgids[1] = i2->i_gid;
185 for (i = 0; i < current_ngroups; i++) {
186 if (suppgids[0] == -1) {
187 if (current_groups[i] != suppgids[1])
188 suppgids[0] = current_groups[i];
191 if (suppgids[1] == -1) {
192 if (current_groups[i] != suppgids[0])
193 suppgids[1] = current_groups[i];
201 * this function prepares md_op_data hint for passing ot down to MD stack.
203 * Note: it zeroes @op_data out before doing anything else, so all additional
204 * initializations of @op_data should be done after it.
206 void ll_prepare_md_op_data(struct md_op_data *op_data, struct inode *i1,
207 struct inode *i2, const char *name, int namelen,
211 LASSERT(op_data != NULL);
213 memset(op_data, 0, sizeof(*op_data));
214 ll_i2gids(op_data->suppgids, i1, i2);
215 op_data->fid1 = ll_i2info(i1)->lli_fid;
217 /* @i2 may be NULL. In this case caller itself has to initialize ->fid2
220 op_data->fid2 = ll_i2info(i2)->lli_fid;
222 op_data->name = name;
223 op_data->namelen = namelen;
224 op_data->create_mode = mode;
225 op_data->mod_time = CURRENT_SECONDS;
228 static void ll_d_add(struct dentry *de, struct inode *inode)
230 CDEBUG(D_DENTRY, "adding inode %p to dentry %p\n", inode, de);
232 if (!list_empty(&de->d_alias)) {
233 spin_unlock(&dcache_lock);
234 CERROR("dentry %.*s %p alias next %p, prev %p\n",
235 de->d_name.len, de->d_name.name, de,
236 de->d_alias.next, de->d_alias.prev);
240 list_add(&de->d_alias, &inode->i_dentry);
244 if (!d_unhashed(de)) {
245 spin_unlock(&dcache_lock);
246 CERROR("dentry %.*s %p hash next %p\n",
247 de->d_name.len, de->d_name.name, de, de->d_hash.next);
253 /* 2.6.15 and prior versions have buggy d_instantiate_unique that leaks an inode
254 * if suitable alias is found. But we are not going to fix it by just freeing
255 * such inode, because if some vendor's kernel contains this bugfix already,
256 * we will break everything then. We will use our own reimplementation
258 #if !defined(HAVE_D_ADD_UNIQUE) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
259 /* Search "inode"'s alias list for a dentry that has the same name and parent as
260 * de. If found, return it. If not found, return de. */
261 struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
263 struct list_head *tmp;
265 spin_lock(&dcache_lock);
266 list_for_each(tmp, &inode->i_dentry) {
267 struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
269 /* We are called here with 'de' already on the aliases list. */
275 if (dentry->d_parent != de->d_parent)
278 if (dentry->d_name.len != de->d_name.len)
281 if (memcmp(dentry->d_name.name, de->d_name.name,
282 de->d_name.len) != 0)
288 dentry->d_flags &= ~DCACHE_LUSTRE_INVALID;
289 unlock_dentry(dentry);
290 __d_rehash(dentry, 0); /* avoid taking dcache_lock inside */
291 spin_unlock(&dcache_lock);
293 CDEBUG(D_DENTRY, "alias dentry %.*s (%p) parent %p inode %p "
294 "refc %d\n", de->d_name.len, de->d_name.name, de,
295 de->d_parent, de->d_inode, atomic_read(&de->d_count));
301 spin_unlock(&dcache_lock);
306 struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
308 struct dentry *dentry;
310 dentry = d_add_unique(de, inode);
313 dentry->d_flags &= ~DCACHE_LUSTRE_INVALID;
314 unlock_dentry(dentry);
317 return dentry?dentry:de;
321 static int lookup_it_finish(struct ptlrpc_request *request, int offset,
322 struct lookup_intent *it, void *data)
324 struct it_cb_data *icbd = data;
325 struct dentry **de = icbd->icbd_childp;
326 struct inode *parent = icbd->icbd_parent;
327 struct ll_sb_info *sbi = ll_i2sbi(parent);
328 struct inode *inode = NULL;
331 /* NB 1 request reference will be taken away by ll_intent_lock()
333 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
336 rc = ll_prep_inode(&inode, request, offset,
341 CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%lu/%u)\n",
342 inode, inode->i_ino, inode->i_generation);
343 md_set_lock_data(sbi->ll_md_exp,
344 &it->d.lustre.it_lock_handle, inode);
346 /* We used to query real size from OSTs here, but actually
347 this is not needed. For stat() calls size would be updated
348 from subsequent do_revalidate()->ll_inode_revalidate_it() in
350 vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
351 Everybody else who needs correct file size would call
352 ll_glimpse_size or some equivalent themselves anyway.
353 Also see bug 7198. */
355 *de = ll_find_alias(inode, *de);
358 /* Check that parent has UPDATE lock. If there is none, we
359 * cannot afford to hash this dentry (done by ll_d_add) as it
360 * might get picked up later when UPDATE lock will appear */
361 if (ll_have_md_lock(parent, MDS_INODELOCK_UPDATE)) {
362 spin_lock(&dcache_lock);
363 ll_d_add(*de, inode);
364 spin_unlock(&dcache_lock);
366 (*de)->d_inode = NULL;
370 (*de)->d_op = &ll_d_ops;
375 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
376 struct lookup_intent *it, int lookup_flags)
378 struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
379 struct dentry *save = dentry, *retval;
380 struct ptlrpc_request *req = NULL;
381 struct md_op_data *op_data;
382 struct it_cb_data icbd;
386 if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
387 RETURN(ERR_PTR(-ENAMETOOLONG));
389 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),intent=%s\n",
390 dentry->d_name.len, dentry->d_name.name, parent->i_ino,
391 parent->i_generation, parent, LL_IT2STR(it));
393 if (d_mountpoint(dentry))
394 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
396 ll_frob_intent(&it, &lookup_it);
398 icbd.icbd_childp = &dentry;
399 icbd.icbd_parent = parent;
401 OBD_ALLOC_PTR(op_data);
403 RETURN(ERR_PTR(-ENOMEM));
405 /* prepare operatoin hint first */
406 ll_prepare_md_op_data(op_data, parent, NULL, dentry->d_name.name,
407 dentry->d_name.len, lookup_flags);
409 /* allocate new fid for child */
410 if (it->it_op & IT_CREAT ||
411 (it->it_op & IT_OPEN && it->it_create_mode & O_CREAT)) {
412 struct lu_placement_hint hint = { .ph_pname = NULL,
413 .ph_pfid = ll_inode2fid(parent),
414 .ph_cname = &dentry->d_name,
415 .ph_opc = LUSTRE_OPC_CREATE };
417 rc = ll_fid_md_alloc(ll_i2sbi(parent), &op_data->fid2, &hint);
419 CERROR("can't allocate new fid, rc %d\n", rc);
424 it->it_create_mode &= ~current->fs->umask;
426 rc = md_intent_lock(ll_i2mdexp(parent), op_data, NULL, 0, it,
427 lookup_flags, &req, ll_md_blocking_ast, 0);
428 OBD_FREE_PTR(op_data);
431 GOTO(out, retval = ERR_PTR(rc));
433 rc = lookup_it_finish(req, 1, it, &icbd);
435 ll_intent_release(it);
436 GOTO(out, retval = ERR_PTR(rc));
439 if ((it->it_op & IT_OPEN) && dentry->d_inode &&
440 !S_ISREG(dentry->d_inode->i_mode) &&
441 !S_ISDIR(dentry->d_inode->i_mode)) {
442 ll_release_openhandle(dentry, it);
444 ll_lookup_finish_locks(it, dentry);
447 GOTO(out, retval = NULL);
449 GOTO(out, retval = dentry);
452 ptlrpc_req_finished(req);
456 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
457 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
458 struct nameidata *nd)
463 if (nd && nd->flags & LOOKUP_LAST && !(nd->flags & LOOKUP_LINK_NOTLAST))
464 de = ll_lookup_it(parent, dentry, &nd->intent, nd->flags);
466 de = ll_lookup_it(parent, dentry, NULL, 0);
472 /* We depend on "mode" being set with the proper file type/umask by now */
473 static struct inode *ll_create_node(struct inode *dir, const char *name,
474 int namelen, const void *data, int datalen,
475 int mode, __u64 extra,
476 struct lookup_intent *it)
478 struct inode *inode = NULL;
479 struct ptlrpc_request *request = NULL;
480 struct ll_sb_info *sbi = ll_i2sbi(dir);
484 LASSERT(it && it->d.lustre.it_disposition);
486 request = it->d.lustre.it_data;
487 rc = ll_prep_inode(&inode, request, 1, dir->i_sb);
489 GOTO(out, inode = ERR_PTR(rc));
491 LASSERT(list_empty(&inode->i_dentry));
493 /* We asked for a lock on the directory, but were granted a
494 * lock on the inode. Since we finally have an inode pointer,
495 * stuff it in the lock. */
496 CDEBUG(D_DLMTRACE, "setting l_ast_data to inode %p (%lu/%u)\n",
497 inode, inode->i_ino, inode->i_generation);
498 md_set_lock_data(sbi->ll_md_exp,
499 &it->d.lustre.it_lock_handle, inode);
502 ptlrpc_req_finished(request);
507 * By the time this is called, we already have created the directory cache
508 * entry for the new file, but it is so far negative - it has no inode.
510 * We defer creating the OBD object(s) until open, to keep the intent and
511 * non-intent code paths similar, and also because we do not have the MDS
512 * inode number before calling ll_create_node() (which is needed for LOV),
513 * so we would need to do yet another RPC to the MDS to store the LOV EA
514 * data on the MDS. If needed, we would pass the PACKED lmm as data and
515 * lmm_size in datalen (the MDS still has code which will handle that).
517 * If the create succeeds, we fill in the inode information
518 * with d_instantiate().
520 static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode,
521 struct lookup_intent *it)
527 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),intent=%s\n",
528 dentry->d_name.len, dentry->d_name.name, dir->i_ino,
529 dir->i_generation, dir, LL_IT2STR(it));
531 rc = it_open_error(DISP_OPEN_CREATE, it);
535 inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
536 NULL, 0, mode, 0, it);
538 RETURN(PTR_ERR(inode));
541 d_instantiate(dentry, inode);
545 static void ll_update_times(struct ptlrpc_request *request, int offset,
548 struct mdt_body *body = lustre_msg_buf(request->rq_repmsg, offset,
552 if (body->valid & OBD_MD_FLMTIME &&
553 body->mtime > LTIME_S(inode->i_mtime)) {
554 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to "LPU64"\n",
555 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
556 LTIME_S(inode->i_mtime) = body->mtime;
558 if (body->valid & OBD_MD_FLCTIME &&
559 body->ctime > LTIME_S(inode->i_ctime))
560 LTIME_S(inode->i_ctime) = body->ctime;
563 static int ll_mknod_generic(struct inode *dir, struct qstr *name, int mode,
564 unsigned rdev, struct dentry *dchild)
566 struct ptlrpc_request *request = NULL;
567 struct inode *inode = NULL;
568 struct ll_sb_info *sbi = ll_i2sbi(dir);
569 struct md_op_data *op_data;
570 struct lu_placement_hint hint = {
572 .ph_pfid = ll_inode2fid(dir),
574 .ph_opc = LUSTRE_OPC_MKNOD
579 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p) mode %o dev %x\n",
580 name->len, name->name, dir->i_ino, dir->i_generation, dir,
583 mode &= ~current->fs->umask;
585 switch (mode & S_IFMT) {
588 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
593 OBD_ALLOC_PTR(op_data);
596 ll_prepare_md_op_data(op_data, dir, NULL, name->name,
598 err = ll_fid_md_alloc(sbi, &op_data->fid2, &hint);
601 err = md_create(sbi->ll_md_exp, op_data, NULL, 0, mode,
602 current->fsuid, current->fsgid,
603 current->cap_effective, rdev, &request);
604 OBD_FREE_PTR(op_data);
607 ll_update_times(request, 0, dir);
610 err = ll_prep_inode(&inode, request, 0,
615 d_instantiate(dchild, inode);
624 ptlrpc_req_finished(request);
628 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
629 static int ll_create_nd(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
631 if (!nd || !nd->intent.d.lustre.it_disposition) {
632 /* No saved request? Just mknod the file */
633 return ll_mknod_generic(dir, &dentry->d_name, mode, 0, dentry);
636 return ll_create_it(dir, dentry, mode, &nd->intent);
640 static int ll_symlink_generic(struct inode *dir, struct dentry *dchild,
643 struct qstr *name = &dchild->d_name;
644 struct lu_placement_hint hint = { .ph_pname = NULL,
645 .ph_pfid = ll_inode2fid(dir),
647 .ph_opc = LUSTRE_OPC_SYMLINK };
649 struct ptlrpc_request *request = NULL;
650 struct ll_sb_info *sbi = ll_i2sbi(dir);
651 struct inode *inode = NULL;
652 struct md_op_data *op_data;
656 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),target=%s\n",
657 name->len, name->name, dir->i_ino, dir->i_generation,
660 OBD_ALLOC_PTR(op_data);
664 ll_prepare_md_op_data(op_data, dir, NULL,
665 name->name, name->len, 0);
667 /* allocate new fid */
668 err = ll_fid_md_alloc(ll_i2sbi(dir), &op_data->fid2, &hint);
670 CERROR("can't allocate new fid, rc %d\n", err);
674 err = md_create(sbi->ll_md_exp, op_data,
675 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
676 current->fsuid, current->fsgid, current->cap_effective,
678 OBD_FREE_PTR(op_data);
680 ll_update_times(request, 0, dir);
683 err = ll_prep_inode(&inode, request, 0,
686 d_instantiate(dchild, inode);
690 ptlrpc_req_finished(request);
694 static int ll_link_generic(struct inode *src, struct inode *dir,
697 struct ll_sb_info *sbi = ll_i2sbi(dir);
698 struct ptlrpc_request *request = NULL;
699 struct md_op_data *op_data;
704 "VFS Op: inode=%lu/%u(%p), dir=%lu/%u(%p), target=%.*s\n",
705 src->i_ino, src->i_generation, src, dir->i_ino,
706 dir->i_generation, dir, name->len, name->name);
708 OBD_ALLOC_PTR(op_data);
711 ll_prepare_md_op_data(op_data, src, dir, name->name,
713 err = md_link(sbi->ll_md_exp, op_data, &request);
714 OBD_FREE_PTR(op_data);
716 ll_update_times(request, 0, dir);
718 ptlrpc_req_finished(request);
722 static int ll_mkdir_generic(struct inode *dir, struct qstr *name,
723 int mode, struct dentry *dchild)
726 struct lu_placement_hint hint = { .ph_pname = NULL,
727 .ph_pfid = ll_inode2fid(dir),
729 .ph_opc = LUSTRE_OPC_MKDIR };
730 struct ptlrpc_request *request = NULL;
731 struct ll_sb_info *sbi = ll_i2sbi(dir);
732 struct inode *inode = NULL;
733 struct md_op_data *op_data;
736 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
737 name->len, name->name, dir->i_ino, dir->i_generation, dir);
739 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
741 OBD_ALLOC_PTR(op_data);
744 ll_prepare_md_op_data(op_data, dir, NULL,
745 name->name, name->len, 0);
747 /* allocate new fid */
748 err = ll_fid_md_alloc(ll_i2sbi(dir), &op_data->fid2, &hint);
750 CERROR("can't allocate new fid, rc %d\n", err);
754 err = md_create(sbi->ll_md_exp, op_data, NULL, 0, mode,
755 current->fsuid, current->fsgid,
756 current->cap_effective, 0, &request);
757 OBD_FREE_PTR(op_data);
758 ll_update_times(request, 0, dir);
759 if (!err && dchild) {
760 err = ll_prep_inode(&inode, request, 0,
764 d_instantiate(dchild, inode);
768 ptlrpc_req_finished(request);
772 static int ll_rmdir_generic(struct inode *dir, struct dentry *dparent,
775 struct ptlrpc_request *request = NULL;
776 struct md_op_data *op_data;
777 struct dentry *dentry;
780 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
781 name->len, name->name, dir->i_ino, dir->i_generation, dir);
783 /* Check if we have something mounted at the dir we are going to delete
784 * In such a case there would always be dentry present. */
786 dentry = d_lookup(dparent, name);
788 int mounted = d_mountpoint(dentry);
795 OBD_ALLOC_PTR(op_data);
799 ll_prepare_md_op_data(op_data, dir, NULL, name->name,
801 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
802 OBD_FREE_PTR(op_data);
804 ll_update_times(request, 0, dir);
805 ptlrpc_req_finished(request);
809 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
811 struct mdt_body *body;
812 struct lov_mds_md *eadata;
813 struct lov_stripe_md *lsm = NULL;
814 struct obd_trans_info oti = { 0 };
819 /* req is swabbed so this is safe */
820 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body));
822 if (!(body->valid & OBD_MD_FLEASIZE))
825 if (body->eadatasize == 0) {
826 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
827 GOTO(out, rc = -EPROTO);
830 /* The MDS sent back the EA because we unlinked the last reference
831 * to this file. Use this EA to unlink the objects on the OST.
832 * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
833 * check it is complete and sensible. */
834 eadata = lustre_swab_repbuf(request, 1, body->eadatasize, NULL);
835 LASSERT(eadata != NULL);
836 if (eadata == NULL) {
837 CERROR("Can't unpack MDS EA data\n");
838 GOTO(out, rc = -EPROTO);
841 rc = obd_unpackmd(ll_i2dtexp(dir), &lsm, eadata, body->eadatasize);
843 CERROR("obd_unpackmd: %d\n", rc);
846 LASSERT(rc >= sizeof(*lsm));
848 rc = obd_checkmd(ll_i2dtexp(dir), ll_i2mdexp(dir), lsm);
850 GOTO(out_free_memmd, rc);
854 GOTO(out_free_memmd, rc = -ENOMEM);
856 oa->o_id = lsm->lsm_object_id;
857 oa->o_mode = body->mode & S_IFMT;
858 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
860 if (body->valid & OBD_MD_FLCOOKIE) {
861 oa->o_valid |= OBD_MD_FLCOOKIE;
863 lustre_msg_buf(request->rq_repmsg, 2,
864 sizeof(struct llog_cookie) *
865 lsm->lsm_stripe_count);
866 if (oti.oti_logcookies == NULL) {
867 oa->o_valid &= ~OBD_MD_FLCOOKIE;
868 body->valid &= ~OBD_MD_FLCOOKIE;
872 rc = obd_destroy(ll_i2dtexp(dir), oa, lsm, &oti, ll_i2mdexp(dir));
875 CERROR("obd destroy objid "LPX64" error %d\n",
876 lsm->lsm_object_id, rc);
878 obd_free_memmd(ll_i2dtexp(dir), &lsm);
883 static int ll_unlink_generic(struct inode * dir, struct qstr *name)
885 struct ptlrpc_request *request = NULL;
886 struct md_op_data *op_data;
889 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
890 name->len, name->name, dir->i_ino, dir->i_generation, dir);
892 OBD_ALLOC_PTR(op_data);
896 ll_prepare_md_op_data(op_data, dir, NULL, name->name, name->len, 0);
897 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
898 OBD_FREE_PTR(op_data);
903 ll_update_times(request, 0, dir);
905 rc = ll_objects_destroy(request, dir);
907 ptlrpc_req_finished(request);
911 static int ll_rename_generic(struct inode *src, struct qstr *src_name,
912 struct inode *tgt, struct qstr *tgt_name)
914 struct ptlrpc_request *request = NULL;
915 struct ll_sb_info *sbi = ll_i2sbi(src);
916 struct md_op_data *op_data;
919 CDEBUG(D_VFSTRACE,"VFS Op:oldname=%.*s,src_dir=%lu/%u(%p),newname=%.*s,"
920 "tgt_dir=%lu/%u(%p)\n", src_name->len, src_name->name,
921 src->i_ino, src->i_generation, src, tgt_name->len,
922 tgt_name->name, tgt->i_ino, tgt->i_generation, tgt);
924 OBD_ALLOC_PTR(op_data);
928 ll_prepare_md_op_data(op_data, src, tgt, NULL, 0, 0);
929 err = md_rename(sbi->ll_md_exp, op_data,
930 src_name->name, src_name->len,
931 tgt_name->name, tgt_name->len, &request);
932 OBD_FREE_PTR(op_data);
934 ll_update_times(request, 0, src);
935 ll_update_times(request, 0, tgt);
936 err = ll_objects_destroy(request, src);
939 ptlrpc_req_finished(request);
944 static int ll_mknod_raw(struct nameidata *nd, int mode, dev_t rdev)
946 return ll_mknod_generic(nd->dentry->d_inode, &nd->last, mode,rdev,NULL);
948 static int ll_rename_raw(struct nameidata *srcnd, struct nameidata *tgtnd)
950 return ll_rename_generic(srcnd->dentry->d_inode, &srcnd->last,
951 tgtnd->dentry->d_inode, &tgtnd->last);
953 static int ll_link_raw(struct nameidata *srcnd, struct nameidata *tgtnd)
955 return ll_link_generic(srcnd->dentry->d_inode, tgtnd->dentry->d_inode,
958 static int ll_symlink_raw(struct nameidata *nd, const char *tgt)
962 static int ll_rmdir_raw(struct nameidata *nd)
964 return ll_rmdir_generic(nd->dentry->d_inode, nd->dentry, &nd->last);
966 static int ll_mkdir_raw(struct nameidata *nd, int mode)
968 return ll_mkdir_generic(nd->dentry->d_inode, &nd->last, mode, NULL);
970 static int ll_unlink_raw(struct nameidata *nd)
972 return ll_unlink_generic(nd->dentry->d_inode, &nd->last);
975 static int ll_mknod(struct inode *dir, struct dentry *dchild, int mode,
978 return ll_mknod_generic(dir, &dchild->d_name, mode,
979 old_encode_dev(rdev), dchild);
982 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
983 static int ll_unlink(struct inode * dir, struct dentry *dentry)
985 return ll_unlink_generic(dir, &dentry->d_name);
987 static int ll_mkdir(struct inode *dir, struct dentry *dentry, int mode)
989 return ll_mkdir_generic(dir, &dentry->d_name, mode, dentry);
991 static int ll_rmdir(struct inode *dir, struct dentry *dentry)
993 return ll_rmdir_generic(dir, NULL, &dentry->d_name);
995 static int ll_symlink(struct inode *dir, struct dentry *dentry,
998 return ll_symlink_generic(dir, dentry, oldname);
1000 static int ll_link(struct dentry *old_dentry, struct inode *dir,
1001 struct dentry *new_dentry)
1003 return ll_link_generic(old_dentry->d_inode, dir, &new_dentry->d_name);
1005 static int ll_rename(struct inode *old_dir, struct dentry *old_dentry,
1006 struct inode *new_dir, struct dentry *new_dentry)
1008 return ll_rename_generic(old_dir, &old_dentry->d_name, new_dir,
1009 &new_dentry->d_name);
1013 struct inode_operations ll_dir_inode_operations = {
1014 .link_raw = ll_link_raw,
1015 .unlink_raw = ll_unlink_raw,
1016 .symlink_raw = ll_symlink_raw,
1017 .mkdir_raw = ll_mkdir_raw,
1018 .rmdir_raw = ll_rmdir_raw,
1019 .mknod_raw = ll_mknod_raw,
1021 .rename_raw = ll_rename_raw,
1022 .setattr = ll_setattr,
1023 .setattr_raw = ll_setattr_raw,
1024 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1025 .create_it = ll_create_it,
1026 .lookup_it = ll_lookup_it,
1027 .revalidate_it = ll_inode_revalidate_it,
1029 .lookup = ll_lookup_nd,
1030 .create = ll_create_nd,
1031 .getattr_it = ll_getattr_it,
1032 /* We need all these non-raw things for NFSD, to not patch it. */
1033 .unlink = ll_unlink,
1036 .symlink = ll_symlink,
1038 .rename = ll_rename,
1039 .setattr = ll_setattr,
1040 .getattr = ll_getattr,
1042 .permission = ll_inode_permission,
1043 .setxattr = ll_setxattr,
1044 .getxattr = ll_getxattr,
1045 .listxattr = ll_listxattr,
1046 .removexattr = ll_removexattr,
1049 struct inode_operations ll_special_inode_operations = {
1050 .setattr_raw = ll_setattr_raw,
1051 .setattr = ll_setattr,
1052 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1053 .getattr_it = ll_getattr_it,
1055 .revalidate_it = ll_inode_revalidate_it,
1057 .permission = ll_inode_permission,
1058 .setxattr = ll_setxattr,
1059 .getxattr = ll_getxattr,
1060 .listxattr = ll_listxattr,
1061 .removexattr = ll_removexattr,