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 <linux/obd_support.h>
33 #include <linux/lustre_lite.h>
34 #include <linux/lustre_dlm.h>
35 #include <linux/lustre_version.h>
36 #include "llite_internal.h"
40 /* called from iget{4,5_locked}->find_inode() under inode_lock spinlock */
41 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
42 static int ll_test_inode(struct inode *inode, unsigned long ino, void *opaque)
44 static int ll_test_inode(struct inode *inode, void *opaque)
47 static int last_ino, last_gen, last_count;
48 struct lustre_md *md = opaque;
50 if (!(md->body->valid & (OBD_MD_FLGENER | OBD_MD_FLID))) {
51 CERROR("MDS body missing inum or generation\n");
55 if (last_ino == md->body->ino && last_gen == md->body->generation &&
60 CDEBUG(D_VFSTRACE, "compared %u/%u %u times\n",
61 last_ino, last_gen, last_count);
63 last_ino = md->body->ino;
64 last_gen = md->body->generation;
66 "comparing inode %p ino %lu/%u to body "LPU64"/%u\n",
67 inode, inode->i_ino, inode->i_generation,
68 md->body->ino, md->body->generation);
71 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
72 if (inode->i_ino != md->body->ino)
75 if (inode->i_generation != md->body->generation) {
76 struct ll_sb_info *sbi = ll_i2sbi(inode);
77 struct ll_inode_info *lli = ll_i2info(inode);
79 if (inode->i_state & (I_FREEING | I_CLEAR))
82 atomic_inc(&inode->i_count);
84 inode->i_state |= I_FREEING;
85 LASSERT(list_empty(&lli->lli_dead_list));
86 /* add "duplicate" inode into deathrow for destroy */
87 spin_lock(&sbi->ll_deathrow_lock);
88 list_add(&lli->lli_dead_list, &sbi->ll_deathrow);
89 spin_unlock(&sbi->ll_deathrow_lock);
91 /* remove inode from dirty/io lists */
92 list_del_init(&inode->i_list);
97 /* Apply the attributes in 'opaque' to this inode */
98 if (!(inode->i_state & (I_FREEING | I_CLEAR)))
99 ll_update_inode(inode, md);
103 extern struct dentry_operations ll_d_ops;
105 int ll_unlock(__u32 mode, struct lustre_handle *lockh)
109 ldlm_lock_decref(lockh, mode);
114 /* Get an inode by inode number (already instantiated by the intent lookup).
115 * Returns inode or NULL
117 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
118 int ll_set_inode(struct inode *inode, void *opaque)
120 ll_read_inode2(inode, opaque);
124 struct inode *ll_iget(struct super_block *sb, ino_t hash,
125 struct lustre_md *md)
130 inode = iget5_locked(sb, hash, ll_test_inode, ll_set_inode, md);
133 if (inode->i_state & I_NEW)
134 unlock_new_inode(inode);
135 CDEBUG(D_VFSTRACE, "inode: %lu/%u(%p)\n", inode->i_ino,
136 inode->i_generation, inode);
142 struct inode *ll_iget(struct super_block *sb, ino_t hash,
143 struct lustre_md *md)
147 inode = iget4(sb, hash, ll_test_inode, md);
149 CDEBUG(D_VFSTRACE, "inode: %lu/%u(%p)\n", inode->i_ino,
150 inode->i_generation, inode);
155 int ll_mdc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
156 void *data, int flag)
159 struct lustre_handle lockh;
163 case LDLM_CB_BLOCKING:
164 ldlm_lock2handle(lock, &lockh);
165 rc = ldlm_cli_cancel(&lockh);
167 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
171 case LDLM_CB_CANCELING: {
172 struct inode *inode = ll_inode_from_lock(lock);
173 __u64 bits = lock->l_policy_data.l_inodebits.bits;
175 /* Invalidate all dentries associated with this inode */
181 struct ll_inode_info *lli;
183 lli = ll_i2info(inode);
185 /* DLM locks are taken using version component as well,
186 * so we use fid_num() instead of fid_oid(). */
187 if (lock->l_resource->lr_name.name[0] != fid_seq(&lli->lli_fid) ||
188 lock->l_resource->lr_name.name[1] != fid_num(&lli->lli_fid)) {
189 LDLM_ERROR(lock, "data mismatch with object "DLID3" (%p)",
190 PLID3(&lli->lli_fid), inode);
194 if (lock->l_resource->lr_name.name[0] != inode->i_ino ||
195 lock->l_resource->lr_name.name[1] != inode->i_generation) {
196 LDLM_ERROR(lock, "data mismatch with object %lu/%u (%p)",
197 inode->i_ino, inode->i_generation, inode);
201 if (bits & MDS_INODELOCK_UPDATE)
202 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK,
203 &(ll_i2info(inode)->lli_flags));
206 if (S_ISDIR(inode->i_mode) &&
207 (bits & MDS_INODELOCK_UPDATE)) {
208 CDEBUG(D_INODE, "invalidating inode %lu\n",
210 truncate_inode_pages(inode->i_mapping, 0);
213 if (inode->i_sb->s_root &&
214 inode != inode->i_sb->s_root->d_inode &&
215 (bits & MDS_INODELOCK_LOOKUP))
216 ll_unhash_aliases(inode);
227 int ll_mdc_cancel_unused(struct lustre_handle *conn, struct inode *inode,
228 int flags, void *opaque)
230 struct ldlm_res_id res_id =
231 { .name = {inode->i_ino, inode->i_generation} };
232 struct obd_device *obddev = class_conn2obd(conn);
235 RETURN(ldlm_cli_cancel_unused(obddev->obd_namespace, &res_id, flags,
239 /* Pack the required supplementary groups into the supplied groups array.
240 * If we don't need to use the groups from the target inode(s) then we
241 * instead pack one or more groups from the user's supplementary group
242 * array in case it might be useful. Not needed if doing an MDS-side upcall. */
243 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
248 LASSERT(suppgids != NULL);
250 if (in_group_p(i1->i_gid))
251 suppgids[0] = i1->i_gid;
256 if (in_group_p(i2->i_gid))
257 suppgids[1] = i2->i_gid;
264 for (i = 0; i < current_ngroups; i++) {
265 if (suppgids[0] == -1) {
266 if (current_groups[i] != suppgids[1])
267 suppgids[0] = current_groups[i];
270 if (suppgids[1] == -1) {
271 if (current_groups[i] != suppgids[0])
272 suppgids[1] = current_groups[i];
279 void ll_prepare_mdc_op_data(struct mdc_op_data *data, struct inode *i1,
280 struct inode *i2, const char *name, int namelen,
285 ll_i2gids(data->suppgids, i1, i2);
286 ll_inode2fid(&data->fid1, i1);
289 ll_inode2fid(&data->fid2, i2);
291 memset(&data->fid2, 0, sizeof(data->fid2));
294 data->namelen = namelen;
295 data->create_mode = mode;
296 data->mod_time = CURRENT_SECONDS;
299 static void ll_d_add(struct dentry *de, struct inode *inode)
301 CDEBUG(D_DENTRY, "adding inode %p to dentry %p\n", inode, de);
303 if (!list_empty(&de->d_alias)) {
304 spin_unlock(&dcache_lock);
305 CERROR("dentry %.*s %p alias next %p, prev %p\n",
306 de->d_name.len, de->d_name.name, de,
307 de->d_alias.next, de->d_alias.prev);
311 list_add(&de->d_alias, &inode->i_dentry);
315 if (!d_unhashed(de)) {
316 spin_unlock(&dcache_lock);
317 CERROR("dentry %.*s %p hash next %p\n",
318 de->d_name.len, de->d_name.name, de, de->d_hash.next);
324 /* Search "inode"'s alias list for a dentry that has the same name and parent as
325 * de. If found, return it. If not found, return de. */
326 struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
328 struct list_head *tmp;
330 spin_lock(&dcache_lock);
331 list_for_each(tmp, &inode->i_dentry) {
332 struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
334 /* We are called here with 'de' already on the aliases list. */
340 if (dentry->d_parent != de->d_parent)
343 if (dentry->d_name.len != de->d_name.len)
346 if (memcmp(dentry->d_name.name, de->d_name.name,
347 de->d_name.len) != 0)
353 dentry->d_flags &= ~DCACHE_LUSTRE_INVALID;
354 unlock_dentry(dentry);
355 __d_rehash(dentry, 0); /* avoid taking dcache_lock inside */
356 spin_unlock(&dcache_lock);
358 CDEBUG(D_DENTRY, "alias dentry %.*s (%p) parent %p inode %p "
359 "refc %d\n", de->d_name.len, de->d_name.name, de,
360 de->d_parent, de->d_inode, atomic_read(&de->d_count));
366 spin_unlock(&dcache_lock);
371 static int lookup_it_finish(struct ptlrpc_request *request, int offset,
372 struct lookup_intent *it, void *data)
374 struct it_cb_data *icbd = data;
375 struct dentry **de = icbd->icbd_childp;
376 struct inode *parent = icbd->icbd_parent;
377 struct ll_sb_info *sbi = ll_i2sbi(parent);
378 struct inode *inode = NULL;
381 /* NB 1 request reference will be taken away by ll_intent_lock()
383 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
386 rc = ll_prep_inode(sbi->ll_osc_exp, &inode, request, offset,
391 CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%lu/%u)\n",
392 inode, inode->i_ino, inode->i_generation);
393 mdc_set_lock_data(&it->d.lustre.it_lock_handle, inode);
395 /* We used to query real size from OSTs here, but actually
396 this is not needed. For stat() calls size would be updated
397 from subsequent do_revalidate()->ll_inode_revalidate_it() in
399 vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
400 Everybody else who needs correct file size would call
401 ll_glimpse_size or some equivalent themselves anyway.
402 Also see bug 7198. */
404 *de = ll_find_alias(inode, *de);
407 spin_lock(&dcache_lock);
408 ll_d_add(*de, inode);
409 spin_unlock(&dcache_lock);
413 (*de)->d_op = &ll_d_ops;
418 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
419 struct lookup_intent *it, int lookup_flags)
421 struct dentry *save = dentry, *retval;
422 struct mdc_op_data op_data;
423 struct it_cb_data icbd;
424 struct ptlrpc_request *req = NULL;
425 struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
429 if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
430 RETURN(ERR_PTR(-ENAMETOOLONG));
432 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),intent=%s\n",
433 dentry->d_name.len, dentry->d_name.name, parent->i_ino,
434 parent->i_generation, parent, LL_IT2STR(it));
436 if (d_mountpoint(dentry))
437 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
439 ll_frob_intent(&it, &lookup_it);
441 icbd.icbd_childp = &dentry;
442 icbd.icbd_parent = parent;
444 ll_prepare_mdc_op_data(&op_data, parent, NULL, dentry->d_name.name,
445 dentry->d_name.len, lookup_flags);
447 it->it_create_mode &= ~current->fs->umask;
449 rc = mdc_intent_lock(ll_i2mdcexp(parent), &op_data, NULL, 0, it,
450 lookup_flags, &req, ll_mdc_blocking_ast, 0);
453 GOTO(out, retval = ERR_PTR(rc));
455 rc = lookup_it_finish(req, 1, it, &icbd);
457 ll_intent_release(it);
458 GOTO(out, retval = ERR_PTR(rc));
461 ll_lookup_finish_locks(it, dentry);
464 GOTO(out, retval = NULL);
466 GOTO(out, retval = dentry);
469 ptlrpc_req_finished(req);
473 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
474 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
475 struct nameidata *nd)
480 if (nd && nd->flags & LOOKUP_LAST && !(nd->flags & LOOKUP_LINK_NOTLAST))
481 de = ll_lookup_it(parent, dentry, &nd->intent, nd->flags);
483 de = ll_lookup_it(parent, dentry, NULL, 0);
489 /* We depend on "mode" being set with the proper file type/umask by now */
490 static struct inode *ll_create_node(struct inode *dir, const char *name,
491 int namelen, const void *data, int datalen,
492 int mode, __u64 extra,
493 struct lookup_intent *it)
495 struct inode *inode = NULL;
496 struct ptlrpc_request *request = NULL;
497 struct ll_sb_info *sbi = ll_i2sbi(dir);
501 LASSERT(it && it->d.lustre.it_disposition);
503 request = it->d.lustre.it_data;
504 rc = ll_prep_inode(sbi->ll_osc_exp, &inode, request, 1, dir->i_sb);
506 GOTO(out, inode = ERR_PTR(rc));
508 LASSERT(list_empty(&inode->i_dentry));
510 /* We asked for a lock on the directory, but were granted a
511 * lock on the inode. Since we finally have an inode pointer,
512 * stuff it in the lock. */
513 CDEBUG(D_DLMTRACE, "setting l_ast_data to inode %p (%lu/%u)\n",
514 inode, inode->i_ino, inode->i_generation);
515 mdc_set_lock_data(&it->d.lustre.it_lock_handle, inode);
518 ptlrpc_req_finished(request);
523 * By the time this is called, we already have created the directory cache
524 * entry for the new file, but it is so far negative - it has no inode.
526 * We defer creating the OBD object(s) until open, to keep the intent and
527 * non-intent code paths similar, and also because we do not have the MDS
528 * inode number before calling ll_create_node() (which is needed for LOV),
529 * so we would need to do yet another RPC to the MDS to store the LOV EA
530 * data on the MDS. If needed, we would pass the PACKED lmm as data and
531 * lmm_size in datalen (the MDS still has code which will handle that).
533 * If the create succeeds, we fill in the inode information
534 * with d_instantiate().
536 static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode,
537 struct lookup_intent *it)
543 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),intent=%s\n",
544 dentry->d_name.len, dentry->d_name.name, dir->i_ino,
545 dir->i_generation, dir, LL_IT2STR(it));
547 rc = it_open_error(DISP_OPEN_CREATE, it);
551 inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
552 NULL, 0, mode, 0, it);
554 RETURN(PTR_ERR(inode));
557 d_instantiate(dentry, inode);
561 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
562 static int ll_create_nd(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
564 return ll_create_it(dir, dentry, mode, &nd->intent);
568 static void ll_update_times(struct ptlrpc_request *request, int offset,
571 struct mdt_body *body = lustre_msg_buf(request->rq_repmsg, offset,
575 if (body->valid & OBD_MD_FLMTIME &&
576 body->mtime > LTIME_S(inode->i_mtime)) {
577 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to "LPU64"\n",
578 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
579 LTIME_S(inode->i_mtime) = body->mtime;
581 if (body->valid & OBD_MD_FLCTIME &&
582 body->ctime > LTIME_S(inode->i_ctime))
583 LTIME_S(inode->i_ctime) = body->ctime;
586 static int ll_mknod_raw(struct nameidata *nd, int mode, dev_t rdev)
588 struct ptlrpc_request *request = NULL;
589 struct inode *dir = nd->dentry->d_inode;
590 struct ll_sb_info *sbi = ll_i2sbi(dir);
591 struct mdc_op_data op_data;
595 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p) mode %o dev %x\n",
596 nd->last.len, nd->last.name, dir->i_ino, dir->i_generation, dir,
599 mode &= ~current->fs->umask;
601 switch (mode & S_IFMT) {
604 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
609 ll_prepare_mdc_op_data(&op_data, dir, NULL, nd->last.name,
611 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
612 current->fsuid, current->fsgid,
613 current->cap_effective, rdev, &request);
615 ll_update_times(request, 0, dir);
616 ptlrpc_req_finished(request);
627 static int ll_mknod(struct inode *dir, struct dentry *dchild, int mode,
630 struct ptlrpc_request *request = NULL;
631 struct inode *inode = NULL;
632 struct ll_sb_info *sbi = ll_i2sbi(dir);
633 struct mdc_op_data op_data;
637 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
638 dchild->d_name.len, dchild->d_name.name,
639 dir->i_ino, dir->i_generation, dir);
641 mode &= ~current->fs->umask;
643 switch (mode & S_IFMT) {
646 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
651 ll_prepare_mdc_op_data(&op_data, dir, NULL, dchild->d_name.name,
652 dchild->d_name.len, 0);
653 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
654 current->fsuid, current->fsgid,
655 current->cap_effective, rdev, &request);
659 ll_update_times(request, 0, dir);
661 err = ll_prep_inode(sbi->ll_osc_exp, &inode, request, 0,
673 d_instantiate(dchild, inode);
675 ptlrpc_req_finished(request);
679 static int ll_symlink_raw(struct nameidata *nd, const char *tgt)
681 struct inode *dir = nd->dentry->d_inode;
682 struct ptlrpc_request *request = NULL;
683 struct ll_sb_info *sbi = ll_i2sbi(dir);
684 struct mdc_op_data op_data;
688 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),target=%s\n",
689 nd->last.len, nd->last.name, dir->i_ino, dir->i_generation,
692 ll_prepare_mdc_op_data(&op_data, dir, NULL, nd->last.name,
694 err = mdc_create(sbi->ll_mdc_exp, &op_data,
695 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
696 current->fsuid, current->fsgid, current->cap_effective,
699 ll_update_times(request, 0, dir);
701 ptlrpc_req_finished(request);
705 static int ll_link_raw(struct nameidata *srcnd, struct nameidata *tgtnd)
707 struct inode *src = srcnd->dentry->d_inode;
708 struct inode *dir = tgtnd->dentry->d_inode;
709 struct ptlrpc_request *request = NULL;
710 struct mdc_op_data op_data;
712 struct ll_sb_info *sbi = ll_i2sbi(dir);
716 "VFS Op: inode=%lu/%u(%p), dir=%lu/%u(%p), target=%.*s\n",
717 src->i_ino, src->i_generation, src, dir->i_ino,
718 dir->i_generation, dir, tgtnd->last.len, tgtnd->last.name);
720 ll_prepare_mdc_op_data(&op_data, src, dir, tgtnd->last.name,
722 err = mdc_link(sbi->ll_mdc_exp, &op_data, &request);
724 ll_update_times(request, 0, dir);
726 ptlrpc_req_finished(request);
732 static int ll_mkdir_raw(struct nameidata *nd, int mode)
734 struct inode *dir = nd->dentry->d_inode;
735 struct ptlrpc_request *request = NULL;
736 struct ll_sb_info *sbi = ll_i2sbi(dir);
737 struct mdc_op_data op_data;
740 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
741 nd->last.len, nd->last.name, dir->i_ino, dir->i_generation, dir);
743 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
744 ll_prepare_mdc_op_data(&op_data, dir, NULL, nd->last.name,
746 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
747 current->fsuid, current->fsgid, current->cap_effective,
750 ll_update_times(request, 0, dir);
752 ptlrpc_req_finished(request);
756 static int ll_rmdir_raw(struct nameidata *nd)
758 struct inode *dir = nd->dentry->d_inode;
759 struct ptlrpc_request *request = NULL;
760 struct mdc_op_data op_data;
761 struct dentry *dentry;
764 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
765 nd->last.len, nd->last.name, dir->i_ino, dir->i_generation, dir);
767 /* Check if we have something mounted at the dir we are going to delete
768 * In such a case there would always be dentry present. */
769 dentry = d_lookup(nd->dentry, &nd->last);
771 int mounted = d_mountpoint(dentry);
777 ll_prepare_mdc_op_data(&op_data, dir, NULL, nd->last.name,
778 nd->last.len, S_IFDIR);
779 rc = mdc_unlink(ll_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
781 ll_update_times(request, 0, dir);
782 ptlrpc_req_finished(request);
786 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
788 struct mdt_body *body;
789 struct lov_mds_md *eadata;
790 struct lov_stripe_md *lsm = NULL;
791 struct obd_trans_info oti = { 0 };
796 /* req is swabbed so this is safe */
797 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body));
799 if (!(body->valid & OBD_MD_FLEASIZE))
802 if (body->eadatasize == 0) {
803 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
804 GOTO(out, rc = -EPROTO);
807 /* The MDS sent back the EA because we unlinked the last reference
808 * to this file. Use this EA to unlink the objects on the OST.
809 * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
810 * check it is complete and sensible. */
811 eadata = lustre_swab_repbuf(request, 1, body->eadatasize, NULL);
812 LASSERT(eadata != NULL);
813 if (eadata == NULL) {
814 CERROR("Can't unpack MDS EA data\n");
815 GOTO(out, rc = -EPROTO);
818 rc = obd_unpackmd(ll_i2obdexp(dir), &lsm, eadata, body->eadatasize);
820 CERROR("obd_unpackmd: %d\n", rc);
823 LASSERT(rc >= sizeof(*lsm));
825 rc = obd_checkmd(ll_i2obdexp(dir), ll_i2mdcexp(dir), lsm);
827 GOTO(out_free_memmd, rc);
831 GOTO(out_free_memmd, rc = -ENOMEM);
833 oa->o_id = lsm->lsm_object_id;
834 oa->o_mode = body->mode & S_IFMT;
835 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
837 if (body->valid & OBD_MD_FLCOOKIE) {
838 oa->o_valid |= OBD_MD_FLCOOKIE;
840 lustre_msg_buf(request->rq_repmsg, 2,
841 sizeof(struct llog_cookie) *
842 lsm->lsm_stripe_count);
843 if (oti.oti_logcookies == NULL) {
844 oa->o_valid &= ~OBD_MD_FLCOOKIE;
845 body->valid &= ~OBD_MD_FLCOOKIE;
849 rc = obd_destroy(ll_i2obdexp(dir), oa, lsm, &oti, ll_i2mdcexp(dir));
852 CERROR("obd destroy objid "LPX64" error %d\n",
853 lsm->lsm_object_id, rc);
855 obd_free_memmd(ll_i2obdexp(dir), &lsm);
860 static int ll_unlink_raw(struct nameidata *nd)
862 struct inode *dir = nd->dentry->d_inode;
863 struct ptlrpc_request *request = NULL;
864 struct mdc_op_data op_data;
867 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
868 nd->last.len, nd->last.name, dir->i_ino, dir->i_generation, dir);
870 ll_prepare_mdc_op_data(&op_data, dir, NULL, nd->last.name,
872 rc = mdc_unlink(ll_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
876 ll_update_times(request, 0, dir);
878 rc = ll_objects_destroy(request, dir);
880 ptlrpc_req_finished(request);
884 static int ll_rename_raw(struct nameidata *srcnd, struct nameidata *tgtnd)
886 struct inode *src = srcnd->dentry->d_inode;
887 struct inode *tgt = tgtnd->dentry->d_inode;
888 struct ptlrpc_request *request = NULL;
889 struct ll_sb_info *sbi = ll_i2sbi(src);
890 struct mdc_op_data op_data;
893 CDEBUG(D_VFSTRACE,"VFS Op:oldname=%.*s,src_dir=%lu/%u(%p),newname=%.*s,"
894 "tgt_dir=%lu/%u(%p)\n", srcnd->last.len, srcnd->last.name,
895 src->i_ino, src->i_generation, src, tgtnd->last.len,
896 tgtnd->last.name, tgt->i_ino, tgt->i_generation, tgt);
898 ll_prepare_mdc_op_data(&op_data, src, tgt, NULL, 0, 0);
899 err = mdc_rename(sbi->ll_mdc_exp, &op_data,
900 srcnd->last.name, srcnd->last.len,
901 tgtnd->last.name, tgtnd->last.len, &request);
903 ll_update_times(request, 0, src);
904 ll_update_times(request, 0, tgt);
905 err = ll_objects_destroy(request, src);
908 ptlrpc_req_finished(request);
913 struct inode_operations ll_dir_inode_operations = {
914 .link_raw = ll_link_raw,
915 .unlink_raw = ll_unlink_raw,
916 .symlink_raw = ll_symlink_raw,
917 .mkdir_raw = ll_mkdir_raw,
918 .rmdir_raw = ll_rmdir_raw,
919 .mknod_raw = ll_mknod_raw,
921 .rename_raw = ll_rename_raw,
922 .setattr = ll_setattr,
923 .setattr_raw = ll_setattr_raw,
924 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
925 .create_it = ll_create_it,
926 .lookup_it = ll_lookup_it,
927 .revalidate_it = ll_inode_revalidate_it,
929 .lookup = ll_lookup_nd,
930 .create = ll_create_nd,
931 .getattr_it = ll_getattr,
933 .permission = ll_inode_permission,
934 .setxattr = ll_setxattr,
935 .getxattr = ll_getxattr,
936 .listxattr = ll_listxattr,
937 .removexattr = ll_removexattr,