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)
540 struct ptlrpc_request *request = it->d.lustre.it_data;
544 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),intent=%s\n",
545 dentry->d_name.len, dentry->d_name.name, dir->i_ino,
546 dir->i_generation, dir, LL_IT2STR(it));
548 rc = it_open_error(DISP_OPEN_CREATE, it);
552 inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
553 NULL, 0, mode, 0, it);
555 RETURN(PTR_ERR(inode));
558 d_instantiate(dentry, inode);
562 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
563 static int ll_create_nd(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
565 return ll_create_it(dir, dentry, mode, &nd->intent);
569 static void ll_update_times(struct ptlrpc_request *request, int offset,
572 struct mds_body *body = lustre_msg_buf(request->rq_repmsg, offset,
576 if (body->valid & OBD_MD_FLMTIME &&
577 body->mtime > LTIME_S(inode->i_mtime)) {
578 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to "LPU64"\n",
579 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
580 LTIME_S(inode->i_mtime) = body->mtime;
582 if (body->valid & OBD_MD_FLCTIME &&
583 body->ctime > LTIME_S(inode->i_ctime))
584 LTIME_S(inode->i_ctime) = body->ctime;
587 static int ll_mknod_raw(struct nameidata *nd, int mode, dev_t rdev)
589 struct ptlrpc_request *request = NULL;
590 struct inode *dir = nd->dentry->d_inode;
591 struct ll_sb_info *sbi = ll_i2sbi(dir);
592 struct mdc_op_data op_data;
596 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p) mode %o dev %x\n",
597 nd->last.len, nd->last.name, dir->i_ino, dir->i_generation, dir,
600 mode &= ~current->fs->umask;
602 switch (mode & S_IFMT) {
605 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
610 ll_prepare_mdc_op_data(&op_data, dir, NULL, nd->last.name,
612 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
613 current->fsuid, current->fsgid,
614 current->cap_effective, rdev, &request);
616 ll_update_times(request, 0, dir);
617 ptlrpc_req_finished(request);
628 static int ll_mknod(struct inode *dir, struct dentry *dchild, int mode,
631 struct ptlrpc_request *request = NULL;
632 struct inode *inode = NULL;
633 struct ll_sb_info *sbi = ll_i2sbi(dir);
634 struct mdc_op_data op_data;
638 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
639 dchild->d_name.len, dchild->d_name.name,
640 dir->i_ino, dir->i_generation, dir);
642 mode &= ~current->fs->umask;
644 switch (mode & S_IFMT) {
647 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
652 ll_prepare_mdc_op_data(&op_data, dir, NULL, dchild->d_name.name,
653 dchild->d_name.len, 0);
654 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
655 current->fsuid, current->fsgid,
656 current->cap_effective, rdev, &request);
660 ll_update_times(request, 0, dir);
662 err = ll_prep_inode(sbi->ll_osc_exp, &inode, request, 0,
674 d_instantiate(dchild, inode);
676 ptlrpc_req_finished(request);
680 static int ll_symlink_raw(struct nameidata *nd, const char *tgt)
682 struct inode *dir = nd->dentry->d_inode;
683 struct ptlrpc_request *request = NULL;
684 struct ll_sb_info *sbi = ll_i2sbi(dir);
685 struct mdc_op_data op_data;
689 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p),target=%s\n",
690 nd->last.len, nd->last.name, dir->i_ino, dir->i_generation,
693 ll_prepare_mdc_op_data(&op_data, dir, NULL, nd->last.name,
695 err = mdc_create(sbi->ll_mdc_exp, &op_data,
696 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
697 current->fsuid, current->fsgid, current->cap_effective,
700 ll_update_times(request, 0, dir);
702 ptlrpc_req_finished(request);
706 static int ll_link_raw(struct nameidata *srcnd, struct nameidata *tgtnd)
708 struct inode *src = srcnd->dentry->d_inode;
709 struct inode *dir = tgtnd->dentry->d_inode;
710 struct ptlrpc_request *request = NULL;
711 struct mdc_op_data op_data;
713 struct ll_sb_info *sbi = ll_i2sbi(dir);
717 "VFS Op: inode=%lu/%u(%p), dir=%lu/%u(%p), target=%.*s\n",
718 src->i_ino, src->i_generation, src, dir->i_ino,
719 dir->i_generation, dir, tgtnd->last.len, tgtnd->last.name);
721 ll_prepare_mdc_op_data(&op_data, src, dir, tgtnd->last.name,
723 err = mdc_link(sbi->ll_mdc_exp, &op_data, &request);
725 ll_update_times(request, 0, dir);
727 ptlrpc_req_finished(request);
733 static int ll_mkdir_raw(struct nameidata *nd, int mode)
735 struct inode *dir = nd->dentry->d_inode;
736 struct ptlrpc_request *request = NULL;
737 struct ll_sb_info *sbi = ll_i2sbi(dir);
738 struct mdc_op_data op_data;
741 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
742 nd->last.len, nd->last.name, dir->i_ino, dir->i_generation, dir);
744 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
745 ll_prepare_mdc_op_data(&op_data, dir, NULL, nd->last.name,
747 err = mdc_create(sbi->ll_mdc_exp, &op_data, NULL, 0, mode,
748 current->fsuid, current->fsgid, current->cap_effective,
751 ll_update_times(request, 0, dir);
753 ptlrpc_req_finished(request);
757 static int ll_rmdir_raw(struct nameidata *nd)
759 struct inode *dir = nd->dentry->d_inode;
760 struct ptlrpc_request *request = NULL;
761 struct mdc_op_data op_data;
762 struct dentry *dentry;
765 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
766 nd->last.len, nd->last.name, dir->i_ino, dir->i_generation, dir);
768 /* Check if we have something mounted at the dir we are going to delete
769 * In such a case there would always be dentry present. */
770 dentry = d_lookup(nd->dentry, &nd->last);
772 int mounted = d_mountpoint(dentry);
778 ll_prepare_mdc_op_data(&op_data, dir, NULL, nd->last.name,
779 nd->last.len, S_IFDIR);
780 rc = mdc_unlink(ll_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
782 ll_update_times(request, 0, dir);
783 ptlrpc_req_finished(request);
787 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
789 struct mds_body *body;
790 struct lov_mds_md *eadata;
791 struct lov_stripe_md *lsm = NULL;
792 struct obd_trans_info oti = { 0 };
797 /* req is swabbed so this is safe */
798 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body));
800 if (!(body->valid & OBD_MD_FLEASIZE))
803 if (body->eadatasize == 0) {
804 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
805 GOTO(out, rc = -EPROTO);
808 /* The MDS sent back the EA because we unlinked the last reference
809 * to this file. Use this EA to unlink the objects on the OST.
810 * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
811 * check it is complete and sensible. */
812 eadata = lustre_swab_repbuf(request, 1, body->eadatasize, NULL);
813 LASSERT(eadata != NULL);
814 if (eadata == NULL) {
815 CERROR("Can't unpack MDS EA data\n");
816 GOTO(out, rc = -EPROTO);
819 rc = obd_unpackmd(ll_i2obdexp(dir), &lsm, eadata, body->eadatasize);
821 CERROR("obd_unpackmd: %d\n", rc);
824 LASSERT(rc >= sizeof(*lsm));
826 rc = obd_checkmd(ll_i2obdexp(dir), ll_i2mdcexp(dir), lsm);
828 GOTO(out_free_memmd, rc);
832 GOTO(out_free_memmd, rc = -ENOMEM);
834 oa->o_id = lsm->lsm_object_id;
835 oa->o_mode = body->mode & S_IFMT;
836 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
838 if (body->valid & OBD_MD_FLCOOKIE) {
839 oa->o_valid |= OBD_MD_FLCOOKIE;
841 lustre_msg_buf(request->rq_repmsg, 2,
842 sizeof(struct llog_cookie) *
843 lsm->lsm_stripe_count);
844 if (oti.oti_logcookies == NULL) {
845 oa->o_valid &= ~OBD_MD_FLCOOKIE;
846 body->valid &= ~OBD_MD_FLCOOKIE;
850 rc = obd_destroy(ll_i2obdexp(dir), oa, lsm, &oti, ll_i2mdcexp(dir));
853 CERROR("obd destroy objid "LPX64" error %d\n",
854 lsm->lsm_object_id, rc);
856 obd_free_memmd(ll_i2obdexp(dir), &lsm);
861 static int ll_unlink_raw(struct nameidata *nd)
863 struct inode *dir = nd->dentry->d_inode;
864 struct ptlrpc_request *request = NULL;
865 struct mdc_op_data op_data;
868 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
869 nd->last.len, nd->last.name, dir->i_ino, dir->i_generation, dir);
871 ll_prepare_mdc_op_data(&op_data, dir, NULL, nd->last.name,
873 rc = mdc_unlink(ll_i2sbi(dir)->ll_mdc_exp, &op_data, &request);
877 ll_update_times(request, 0, dir);
879 rc = ll_objects_destroy(request, dir);
881 ptlrpc_req_finished(request);
885 static int ll_rename_raw(struct nameidata *srcnd, struct nameidata *tgtnd)
887 struct inode *src = srcnd->dentry->d_inode;
888 struct inode *tgt = tgtnd->dentry->d_inode;
889 struct ptlrpc_request *request = NULL;
890 struct ll_sb_info *sbi = ll_i2sbi(src);
891 struct mdc_op_data op_data;
894 CDEBUG(D_VFSTRACE,"VFS Op:oldname=%.*s,src_dir=%lu/%u(%p),newname=%.*s,"
895 "tgt_dir=%lu/%u(%p)\n", srcnd->last.len, srcnd->last.name,
896 src->i_ino, src->i_generation, src, tgtnd->last.len,
897 tgtnd->last.name, tgt->i_ino, tgt->i_generation, tgt);
899 ll_prepare_mdc_op_data(&op_data, src, tgt, NULL, 0, 0);
900 err = mdc_rename(sbi->ll_mdc_exp, &op_data,
901 srcnd->last.name, srcnd->last.len,
902 tgtnd->last.name, tgtnd->last.len, &request);
904 ll_update_times(request, 0, src);
905 ll_update_times(request, 0, tgt);
906 err = ll_objects_destroy(request, src);
909 ptlrpc_req_finished(request);
914 struct inode_operations ll_dir_inode_operations = {
915 .link_raw = ll_link_raw,
916 .unlink_raw = ll_unlink_raw,
917 .symlink_raw = ll_symlink_raw,
918 .mkdir_raw = ll_mkdir_raw,
919 .rmdir_raw = ll_rmdir_raw,
920 .mknod_raw = ll_mknod_raw,
922 .rename_raw = ll_rename_raw,
923 .setattr = ll_setattr,
924 .setattr_raw = ll_setattr_raw,
925 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
926 .create_it = ll_create_it,
927 .lookup_it = ll_lookup_it,
928 .revalidate_it = ll_inode_revalidate_it,
930 .lookup = ll_lookup_nd,
931 .create = ll_create_nd,
932 .getattr_it = ll_getattr,
934 .permission = ll_inode_permission,
935 .setxattr = ll_setxattr,
936 .getxattr = ll_getxattr,
937 .listxattr = ll_listxattr,
938 .removexattr = ll_removexattr,