4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 #include <linux/sched.h>
40 #include <linux/quotaops.h>
41 #include <linux/highmem.h>
42 #include <linux/pagemap.h>
43 #include <linux/security.h>
45 #define DEBUG_SUBSYSTEM S_LLITE
47 #include "../include/obd_support.h"
48 #include "../include/lustre_fid.h"
49 #include "../include/lustre_lite.h"
50 #include "../include/lustre_dlm.h"
51 #include "../include/lustre_ver.h"
52 #include "llite_internal.h"
54 static int ll_create_it(struct inode *, struct dentry *,
55 int, struct lookup_intent *);
57 /* called from iget5_locked->find_inode() under inode_hash_lock spinlock */
58 static int ll_test_inode(struct inode *inode, void *opaque)
60 struct ll_inode_info *lli = ll_i2info(inode);
61 struct lustre_md *md = opaque;
63 if (unlikely(!(md->body->valid & OBD_MD_FLID))) {
64 CERROR("MDS body missing FID\n");
68 if (!lu_fid_eq(&lli->lli_fid, &md->body->fid1))
74 static int ll_set_inode(struct inode *inode, void *opaque)
76 struct ll_inode_info *lli = ll_i2info(inode);
77 struct mdt_body *body = ((struct lustre_md *)opaque)->body;
79 if (unlikely(!(body->valid & OBD_MD_FLID))) {
80 CERROR("MDS body missing FID\n");
84 lli->lli_fid = body->fid1;
85 if (unlikely(!(body->valid & OBD_MD_FLTYPE))) {
86 CERROR("Can not initialize inode " DFID " without object type: valid = %#llx\n",
87 PFID(&lli->lli_fid), body->valid);
91 inode->i_mode = (inode->i_mode & ~S_IFMT) | (body->mode & S_IFMT);
92 if (unlikely(inode->i_mode == 0)) {
93 CERROR("Invalid inode "DFID" type\n", PFID(&lli->lli_fid));
104 * Get an inode by inode number (already instantiated by the intent lookup).
105 * Returns inode or NULL
107 struct inode *ll_iget(struct super_block *sb, ino_t hash,
108 struct lustre_md *md)
113 inode = iget5_locked(sb, hash, ll_test_inode, ll_set_inode, md);
116 if (inode->i_state & I_NEW) {
119 ll_read_inode2(inode, md);
120 if (S_ISREG(inode->i_mode) &&
121 ll_i2info(inode)->lli_clob == NULL) {
123 "%s: apply lsm %p to inode "DFID".\n",
124 ll_get_fsname(sb, NULL, 0), md->lsm,
125 PFID(ll_inode2fid(inode)));
126 rc = cl_file_inode_init(inode, md);
129 make_bad_inode(inode);
130 unlock_new_inode(inode);
134 unlock_new_inode(inode);
135 } else if (!(inode->i_state & (I_FREEING | I_CLEAR)))
136 ll_update_inode(inode, md);
137 CDEBUG(D_VFSTRACE, "got inode: %p for "DFID"\n",
138 inode, PFID(&md->body->fid1));
143 static void ll_invalidate_negative_children(struct inode *dir)
145 struct dentry *dentry, *tmp_subdir;
146 struct ll_d_hlist_node *p;
149 ll_d_hlist_for_each_entry(dentry, p, &dir->i_dentry, d_u.d_alias) {
150 spin_lock(&dentry->d_lock);
151 if (!list_empty(&dentry->d_subdirs)) {
152 struct dentry *child;
154 list_for_each_entry_safe(child, tmp_subdir,
157 if (child->d_inode == NULL)
158 d_lustre_invalidate(child, 1);
161 spin_unlock(&dentry->d_lock);
163 ll_unlock_dcache(dir);
166 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
167 void *data, int flag)
169 struct lustre_handle lockh;
173 case LDLM_CB_BLOCKING:
174 ldlm_lock2handle(lock, &lockh);
175 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
177 CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc);
181 case LDLM_CB_CANCELING: {
182 struct inode *inode = ll_inode_from_resource_lock(lock);
183 __u64 bits = lock->l_policy_data.l_inodebits.bits;
185 /* Inode is set to lock->l_resource->lr_lvb_inode
186 * for mdc - bug 24555 */
187 LASSERT(lock->l_ast_data == NULL);
192 /* Invalidate all dentries associated with this inode */
193 LASSERT(lock->l_flags & LDLM_FL_CANCELING);
195 if (!fid_res_name_eq(ll_inode2fid(inode),
196 &lock->l_resource->lr_name)) {
197 LDLM_ERROR(lock, "data mismatch with object "DFID"(%p)",
198 PFID(ll_inode2fid(inode)), inode);
202 if (bits & MDS_INODELOCK_XATTR) {
203 ll_xattr_cache_destroy(inode);
204 bits &= ~MDS_INODELOCK_XATTR;
207 /* For OPEN locks we differentiate between lock modes
208 * LCK_CR, LCK_CW, LCK_PR - bug 22891 */
209 if (bits & MDS_INODELOCK_OPEN)
210 ll_have_md_lock(inode, &bits, lock->l_req_mode);
212 if (bits & MDS_INODELOCK_OPEN) {
215 switch (lock->l_req_mode) {
226 LDLM_ERROR(lock, "bad lock mode for OPEN lock");
230 ll_md_real_close(inode, fmode);
233 if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
234 MDS_INODELOCK_LAYOUT | MDS_INODELOCK_PERM))
235 ll_have_md_lock(inode, &bits, LCK_MINMODE);
237 if (bits & MDS_INODELOCK_LAYOUT) {
238 struct cl_object_conf conf = {
239 .coc_opc = OBJECT_CONF_INVALIDATE,
243 rc = ll_layout_conf(inode, &conf);
245 CDEBUG(D_INODE, "cannot invalidate layout of "
247 PFID(ll_inode2fid(inode)), rc);
250 if (bits & MDS_INODELOCK_UPDATE) {
251 struct ll_inode_info *lli = ll_i2info(inode);
253 spin_lock(&lli->lli_lock);
254 lli->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
255 spin_unlock(&lli->lli_lock);
258 if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) {
259 CDEBUG(D_INODE, "invalidating inode %lu\n",
261 truncate_inode_pages(inode->i_mapping, 0);
262 ll_invalidate_negative_children(inode);
265 if ((bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM)) &&
266 inode->i_sb->s_root != NULL &&
267 is_root_inode(inode))
268 ll_invalidate_aliases(inode);
280 __u32 ll_i2suppgid(struct inode *i)
282 if (in_group_p(i->i_gid))
283 return (__u32)from_kgid(&init_user_ns, i->i_gid);
288 /* Pack the required supplementary groups into the supplied groups array.
289 * If we don't need to use the groups from the target inode(s) then we
290 * instead pack one or more groups from the user's supplementary group
291 * array in case it might be useful. Not needed if doing an MDS-side upcall. */
292 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
299 LASSERT(suppgids != NULL);
301 suppgids[0] = ll_i2suppgid(i1);
304 suppgids[1] = ll_i2suppgid(i2);
309 for (i = 0; i < current_ngroups; i++) {
310 if (suppgids[0] == -1) {
311 if (current_groups[i] != suppgids[1])
312 suppgids[0] = current_groups[i];
315 if (suppgids[1] == -1) {
316 if (current_groups[i] != suppgids[0])
317 suppgids[1] = current_groups[i];
326 * try to reuse three types of dentry:
327 * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid
328 * by concurrent .revalidate).
329 * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may
330 * be cleared by others calling d_lustre_revalidate).
331 * 3. DISCONNECTED alias.
333 static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
335 struct dentry *alias, *discon_alias, *invalid_alias;
336 struct ll_d_hlist_node *p;
338 if (ll_d_hlist_empty(&inode->i_dentry))
341 discon_alias = invalid_alias = NULL;
343 ll_lock_dcache(inode);
344 ll_d_hlist_for_each_entry(alias, p, &inode->i_dentry, d_u.d_alias) {
345 LASSERT(alias != dentry);
347 spin_lock(&alias->d_lock);
348 if (alias->d_flags & DCACHE_DISCONNECTED)
349 /* LASSERT(last_discon == NULL); LU-405, bz 20055 */
350 discon_alias = alias;
351 else if (alias->d_parent == dentry->d_parent &&
352 alias->d_name.hash == dentry->d_name.hash &&
353 alias->d_name.len == dentry->d_name.len &&
354 memcmp(alias->d_name.name, dentry->d_name.name,
355 dentry->d_name.len) == 0)
356 invalid_alias = alias;
357 spin_unlock(&alias->d_lock);
362 alias = invalid_alias ?: discon_alias ?: NULL;
364 spin_lock(&alias->d_lock);
366 spin_unlock(&alias->d_lock);
368 ll_unlock_dcache(inode);
374 * Similar to d_splice_alias(), but lustre treats invalid alias
375 * similar to DCACHE_DISCONNECTED, and tries to use it anyway.
377 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de)
383 new = ll_find_alias(inode, de);
393 "Reuse dentry %p inode %p refc %d flags %#x\n",
394 new, new->d_inode, d_count(new), new->d_flags);
402 CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n",
403 de, de->d_inode, d_count(de), de->d_flags);
407 static int ll_lookup_it_finish(struct ptlrpc_request *request,
408 struct lookup_intent *it,
409 struct inode *parent, struct dentry **de)
411 struct inode *inode = NULL;
415 /* NB 1 request reference will be taken away by ll_intent_lock()
417 CDEBUG(D_DENTRY, "it %p it_disposition %x\n", it,
418 it->d.lustre.it_disposition);
419 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
420 rc = ll_prep_inode(&inode, request, (*de)->d_sb, it);
424 ll_set_lock_data(ll_i2sbi(parent)->ll_md_exp, inode, it, &bits);
426 /* We used to query real size from OSTs here, but actually
427 this is not needed. For stat() calls size would be updated
428 from subsequent do_revalidate()->ll_inode_revalidate_it() in
430 vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
431 Everybody else who needs correct file size would call
432 ll_glimpse_size or some equivalent themselves anyway.
433 Also see bug 7198. */
436 /* Only hash *de if it is unhashed (new dentry).
437 * Atoimc_open may passing hashed dentries for open.
439 if (d_unhashed(*de)) {
440 struct dentry *alias;
442 alias = ll_splice_alias(inode, *de);
444 return PTR_ERR(alias);
446 } else if (!it_disposition(it, DISP_LOOKUP_NEG) &&
447 !it_disposition(it, DISP_OPEN_CREATE)) {
448 /* With DISP_OPEN_CREATE dentry will
449 instantiated in ll_create_it. */
450 LASSERT((*de)->d_inode == NULL);
451 d_instantiate(*de, inode);
454 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
455 /* we have lookup look - unhide dentry */
456 if (bits & MDS_INODELOCK_LOOKUP)
457 d_lustre_revalidate(*de);
458 } else if (!it_disposition(it, DISP_OPEN_CREATE)) {
459 /* If file created on server, don't depend on parent UPDATE
460 * lock to unhide it. It is left hidden and next lookup can
461 * find it in ll_splice_alias.
463 /* Check that parent has UPDATE lock. */
464 struct lookup_intent parent_it = {
466 .d.lustre.it_lock_handle = 0 };
468 if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it,
469 &ll_i2info(parent)->lli_fid, NULL)) {
470 d_lustre_revalidate(*de);
471 ll_intent_release(&parent_it);
478 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
479 struct lookup_intent *it, int lookup_flags)
481 struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
482 struct dentry *save = dentry, *retval;
483 struct ptlrpc_request *req = NULL;
484 struct md_op_data *op_data;
488 if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
489 return ERR_PTR(-ENAMETOOLONG);
491 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),intent=%s\n",
492 dentry, parent->i_ino,
493 parent->i_generation, parent, LL_IT2STR(it));
495 if (d_mountpoint(dentry))
496 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
498 if (it == NULL || it->it_op == IT_GETXATTR)
501 if (it->it_op == IT_GETATTR) {
502 rc = ll_statahead_enter(parent, &dentry, 0);
512 if (it->it_op & IT_CREAT)
513 opc = LUSTRE_OPC_CREATE;
515 opc = LUSTRE_OPC_ANY;
517 op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name,
518 dentry->d_name.len, lookup_flags, opc,
521 return (void *)op_data;
523 /* enforce umask if acl disabled or MDS doesn't support umask */
524 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
525 it->it_create_mode &= ~current_umask();
527 rc = md_intent_lock(ll_i2mdexp(parent), op_data, NULL, 0, it,
528 lookup_flags, &req, ll_md_blocking_ast, 0);
529 ll_finish_md_op_data(op_data);
531 retval = ERR_PTR(rc);
535 rc = ll_lookup_it_finish(req, it, parent, &dentry);
537 ll_intent_release(it);
538 retval = ERR_PTR(rc);
542 if ((it->it_op & IT_OPEN) && dentry->d_inode &&
543 !S_ISREG(dentry->d_inode->i_mode) &&
544 !S_ISDIR(dentry->d_inode->i_mode)) {
545 ll_release_openhandle(dentry->d_inode, it);
547 ll_lookup_finish_locks(it, dentry);
556 ptlrpc_req_finished(req);
557 if (it->it_op == IT_GETATTR && (retval == NULL || retval == dentry))
558 ll_statahead_mark(parent, dentry);
562 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
565 struct lookup_intent *itp, it = { .it_op = IT_GETATTR };
568 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),flags=%u\n",
569 dentry, parent->i_ino,
570 parent->i_generation, parent, flags);
572 /* Optimize away (CREATE && !OPEN). Let .create handle the race. */
573 if ((flags & LOOKUP_CREATE) && !(flags & LOOKUP_OPEN))
576 if (flags & (LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE))
580 de = ll_lookup_it(parent, dentry, itp, 0);
583 ll_intent_release(itp);
589 * For cached negative dentry and new dentry, handle lookup/create/open
592 static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
593 struct file *file, unsigned open_flags,
594 umode_t mode, int *opened)
596 struct lookup_intent *it;
598 long long lookup_flags = LOOKUP_OPEN;
601 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),file %p,open_flags %x,mode %x opened %d\n",
603 dir->i_generation, dir, file, open_flags, mode, *opened);
605 it = kzalloc(sizeof(*it), GFP_NOFS);
610 if (open_flags & O_CREAT) {
611 it->it_op |= IT_CREAT;
612 lookup_flags |= LOOKUP_CREATE;
614 it->it_create_mode = (mode & S_IALLUGO) | S_IFREG;
615 it->it_flags = (open_flags & ~O_ACCMODE) | OPEN_FMODE(open_flags);
617 /* Dentry added to dcache tree in ll_lookup_it */
618 de = ll_lookup_it(dir, dentry, it, lookup_flags);
625 if (it_disposition(it, DISP_OPEN_CREATE)) {
626 /* Dentry instantiated in ll_create_it. */
627 rc = ll_create_it(dir, dentry, mode, it);
629 /* We dget in ll_splice_alias. */
635 *opened |= FILE_CREATED;
637 if (dentry->d_inode && it_disposition(it, DISP_OPEN_OPEN)) {
639 if (S_ISFIFO(dentry->d_inode->i_mode)) {
640 /* We cannot call open here as it would
643 if (it_disposition(it, DISP_ENQ_OPEN_REF))
645 (struct ptlrpc_request *)
646 it->d.lustre.it_data);
647 rc = finish_no_open(file, de);
649 file->private_data = it;
650 rc = finish_open(file, dentry, NULL, opened);
651 /* We dget in ll_splice_alias. finish_open takes
652 * care of dget for fd open.
658 rc = finish_no_open(file, de);
663 ll_intent_release(it);
664 OBD_FREE(it, sizeof(*it));
670 /* We depend on "mode" being set with the proper file type/umask by now */
671 static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
673 struct inode *inode = NULL;
674 struct ptlrpc_request *request = NULL;
675 struct ll_sb_info *sbi = ll_i2sbi(dir);
678 LASSERT(it && it->d.lustre.it_disposition);
680 LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
681 request = it->d.lustre.it_data;
682 it_clear_disposition(it, DISP_ENQ_CREATE_REF);
683 rc = ll_prep_inode(&inode, request, dir->i_sb, it);
689 LASSERT(ll_d_hlist_empty(&inode->i_dentry));
691 /* We asked for a lock on the directory, but were granted a
692 * lock on the inode. Since we finally have an inode pointer,
693 * stuff it in the lock. */
694 CDEBUG(D_DLMTRACE, "setting l_ast_data to inode %p (%lu/%u)\n",
695 inode, inode->i_ino, inode->i_generation);
696 ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
698 ptlrpc_req_finished(request);
703 * By the time this is called, we already have created the directory cache
704 * entry for the new file, but it is so far negative - it has no inode.
706 * We defer creating the OBD object(s) until open, to keep the intent and
707 * non-intent code paths similar, and also because we do not have the MDS
708 * inode number before calling ll_create_node() (which is needed for LOV),
709 * so we would need to do yet another RPC to the MDS to store the LOV EA
710 * data on the MDS. If needed, we would pass the PACKED lmm as data and
711 * lmm_size in datalen (the MDS still has code which will handle that).
713 * If the create succeeds, we fill in the inode information
714 * with d_instantiate().
716 static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode,
717 struct lookup_intent *it)
722 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),intent=%s\n",
724 dir->i_generation, dir, LL_IT2STR(it));
726 rc = it_open_error(DISP_OPEN_CREATE, it);
730 inode = ll_create_node(dir, it);
732 return PTR_ERR(inode);
734 d_instantiate(dentry, inode);
738 static void ll_update_times(struct ptlrpc_request *request,
741 struct mdt_body *body = req_capsule_server_get(&request->rq_pill,
745 if (body->valid & OBD_MD_FLMTIME &&
746 body->mtime > LTIME_S(inode->i_mtime)) {
747 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %llu\n",
748 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
749 LTIME_S(inode->i_mtime) = body->mtime;
751 if (body->valid & OBD_MD_FLCTIME &&
752 body->ctime > LTIME_S(inode->i_ctime))
753 LTIME_S(inode->i_ctime) = body->ctime;
756 static int ll_new_node(struct inode *dir, struct dentry *dentry,
757 const char *tgt, int mode, int rdev,
760 struct ptlrpc_request *request = NULL;
761 struct md_op_data *op_data;
762 struct inode *inode = NULL;
763 struct ll_sb_info *sbi = ll_i2sbi(dir);
767 if (unlikely(tgt != NULL))
768 tgt_len = strlen(tgt) + 1;
770 op_data = ll_prep_md_op_data(NULL, dir, NULL,
774 if (IS_ERR(op_data)) {
775 err = PTR_ERR(op_data);
779 err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode,
780 from_kuid(&init_user_ns, current_fsuid()),
781 from_kgid(&init_user_ns, current_fsgid()),
782 cfs_curproc_cap_pack(), rdev, &request);
783 ll_finish_md_op_data(op_data);
787 ll_update_times(request, dir);
789 err = ll_prep_inode(&inode, request, dir->i_sb, NULL);
793 d_instantiate(dentry, inode);
795 ptlrpc_req_finished(request);
800 static int ll_mknod(struct inode *dir, struct dentry *dchild,
801 umode_t mode, dev_t rdev)
805 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p) mode %o dev %x\n",
806 dchild, dir->i_ino, dir->i_generation, dir,
807 mode, old_encode_dev(rdev));
809 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
810 mode &= ~current_umask();
812 switch (mode & S_IFMT) {
814 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
820 err = ll_new_node(dir, dchild, NULL, mode,
821 old_encode_dev(rdev),
832 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD, 1);
838 * Plain create. Intent create is handled in atomic_open.
840 static int ll_create_nd(struct inode *dir, struct dentry *dentry,
841 umode_t mode, bool want_excl)
845 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),flags=%u, excl=%d\n",
847 dir->i_generation, dir, mode, want_excl);
849 rc = ll_mknod(dir, dentry, mode, 0);
851 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
853 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, unhashed %d\n",
854 dentry, d_unhashed(dentry));
859 static inline void ll_get_child_fid(struct dentry *child, struct lu_fid *fid)
862 *fid = *ll_inode2fid(child->d_inode);
868 int ll_rmdir_entry(struct inode *dir, char *name, int namelen)
870 struct ptlrpc_request *request = NULL;
871 struct md_op_data *op_data;
874 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
875 namelen, name, dir->i_ino, dir->i_generation, dir);
877 op_data = ll_prep_md_op_data(NULL, dir, NULL, name, strlen(name),
878 S_IFDIR, LUSTRE_OPC_ANY, NULL);
880 return PTR_ERR(op_data);
881 op_data->op_cli_flags |= CLI_RM_ENTRY;
882 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
883 ll_finish_md_op_data(op_data);
885 ll_update_times(request, dir);
886 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
889 ptlrpc_req_finished(request);
893 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
895 struct mdt_body *body;
896 struct lov_mds_md *eadata;
897 struct lov_stripe_md *lsm = NULL;
898 struct obd_trans_info oti = { 0 };
900 struct obd_capa *oc = NULL;
903 /* req is swabbed so this is safe */
904 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
905 if (!(body->valid & OBD_MD_FLEASIZE))
908 if (body->eadatasize == 0) {
909 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
914 /* The MDS sent back the EA because we unlinked the last reference
915 * to this file. Use this EA to unlink the objects on the OST.
916 * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
917 * check it is complete and sensible. */
918 eadata = req_capsule_server_sized_get(&request->rq_pill, &RMF_MDT_MD,
920 LASSERT(eadata != NULL);
922 rc = obd_unpackmd(ll_i2dtexp(dir), &lsm, eadata, body->eadatasize);
924 CERROR("obd_unpackmd: %d\n", rc);
927 LASSERT(rc >= sizeof(*lsm));
935 oa->o_oi = lsm->lsm_oi;
936 oa->o_mode = body->mode & S_IFMT;
937 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
939 if (body->valid & OBD_MD_FLCOOKIE) {
940 oa->o_valid |= OBD_MD_FLCOOKIE;
942 req_capsule_server_sized_get(&request->rq_pill,
944 sizeof(struct llog_cookie) *
945 lsm->lsm_stripe_count);
946 if (oti.oti_logcookies == NULL) {
947 oa->o_valid &= ~OBD_MD_FLCOOKIE;
948 body->valid &= ~OBD_MD_FLCOOKIE;
952 if (body->valid & OBD_MD_FLOSSCAPA) {
953 rc = md_unpack_capa(ll_i2mdexp(dir), request, &RMF_CAPA2, &oc);
958 rc = obd_destroy(NULL, ll_i2dtexp(dir), oa, lsm, &oti,
959 ll_i2mdexp(dir), oc);
962 CERROR("obd destroy objid "DOSTID" error %d\n",
963 POSTID(&lsm->lsm_oi), rc);
965 obd_free_memmd(ll_i2dtexp(dir), &lsm);
971 /* ll_unlink() doesn't update the inode with the new link count.
972 * Instead, ll_ddelete() and ll_d_iput() will update it based upon if there
973 * is any lock existing. They will recycle dentries and inodes based upon locks
975 static int ll_unlink(struct inode * dir, struct dentry *dentry)
977 struct ptlrpc_request *request = NULL;
978 struct md_op_data *op_data;
980 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
981 dentry, dir->i_ino, dir->i_generation, dir);
983 op_data = ll_prep_md_op_data(NULL, dir, NULL,
986 0, LUSTRE_OPC_ANY, NULL);
988 return PTR_ERR(op_data);
990 ll_get_child_fid(dentry, &op_data->op_fid3);
991 op_data->op_fid2 = op_data->op_fid3;
992 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
993 ll_finish_md_op_data(op_data);
997 ll_update_times(request, dir);
998 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1);
1000 rc = ll_objects_destroy(request, dir);
1002 ptlrpc_req_finished(request);
1006 static int ll_mkdir(struct inode *dir, struct dentry *dentry, ll_umode_t mode)
1010 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
1011 dentry, dir->i_ino, dir->i_generation, dir);
1013 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1014 mode &= ~current_umask();
1015 mode = (mode & (S_IRWXUGO|S_ISVTX)) | S_IFDIR;
1016 err = ll_new_node(dir, dentry, NULL, mode, 0, LUSTRE_OPC_MKDIR);
1019 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR, 1);
1024 static int ll_rmdir(struct inode *dir, struct dentry *dentry)
1026 struct ptlrpc_request *request = NULL;
1027 struct md_op_data *op_data;
1030 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
1031 dentry, dir->i_ino, dir->i_generation, dir);
1033 op_data = ll_prep_md_op_data(NULL, dir, NULL,
1034 dentry->d_name.name,
1036 S_IFDIR, LUSTRE_OPC_ANY, NULL);
1037 if (IS_ERR(op_data))
1038 return PTR_ERR(op_data);
1040 ll_get_child_fid(dentry, &op_data->op_fid3);
1041 op_data->op_fid2 = op_data->op_fid3;
1042 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1043 ll_finish_md_op_data(op_data);
1045 ll_update_times(request, dir);
1046 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
1049 ptlrpc_req_finished(request);
1053 static int ll_symlink(struct inode *dir, struct dentry *dentry,
1054 const char *oldname)
1058 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),target=%.*s\n",
1059 dentry, dir->i_ino, dir->i_generation,
1060 dir, 3000, oldname);
1062 err = ll_new_node(dir, dentry, oldname, S_IFLNK | S_IRWXUGO,
1063 0, LUSTRE_OPC_SYMLINK);
1066 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK, 1);
1071 static int ll_link(struct dentry *old_dentry, struct inode *dir,
1072 struct dentry *new_dentry)
1074 struct inode *src = old_dentry->d_inode;
1075 struct ll_sb_info *sbi = ll_i2sbi(dir);
1076 struct ptlrpc_request *request = NULL;
1077 struct md_op_data *op_data;
1081 "VFS Op: inode=%lu/%u(%p), dir=%lu/%u(%p), target=%pd\n",
1082 src->i_ino, src->i_generation, src, dir->i_ino,
1083 dir->i_generation, dir, new_dentry);
1085 op_data = ll_prep_md_op_data(NULL, src, dir, new_dentry->d_name.name,
1086 new_dentry->d_name.len,
1087 0, LUSTRE_OPC_ANY, NULL);
1088 if (IS_ERR(op_data))
1089 return PTR_ERR(op_data);
1091 err = md_link(sbi->ll_md_exp, op_data, &request);
1092 ll_finish_md_op_data(op_data);
1096 ll_update_times(request, dir);
1097 ll_stats_ops_tally(sbi, LPROC_LL_LINK, 1);
1099 ptlrpc_req_finished(request);
1103 static int ll_rename(struct inode *old_dir, struct dentry *old_dentry,
1104 struct inode *new_dir, struct dentry *new_dentry)
1106 struct ptlrpc_request *request = NULL;
1107 struct ll_sb_info *sbi = ll_i2sbi(old_dir);
1108 struct md_op_data *op_data;
1112 "VFS Op:oldname=%pd,src_dir=%lu/%u(%p),newname=%pd,"
1113 "tgt_dir=%lu/%u(%p)\n", old_dentry,
1114 old_dir->i_ino, old_dir->i_generation, old_dir, new_dentry,
1115 new_dir->i_ino, new_dir->i_generation, new_dir);
1117 op_data = ll_prep_md_op_data(NULL, old_dir, new_dir, NULL, 0, 0,
1118 LUSTRE_OPC_ANY, NULL);
1119 if (IS_ERR(op_data))
1120 return PTR_ERR(op_data);
1122 ll_get_child_fid(old_dentry, &op_data->op_fid3);
1123 ll_get_child_fid(new_dentry, &op_data->op_fid4);
1124 err = md_rename(sbi->ll_md_exp, op_data,
1125 old_dentry->d_name.name,
1126 old_dentry->d_name.len,
1127 new_dentry->d_name.name,
1128 new_dentry->d_name.len, &request);
1129 ll_finish_md_op_data(op_data);
1131 ll_update_times(request, old_dir);
1132 ll_update_times(request, new_dir);
1133 ll_stats_ops_tally(sbi, LPROC_LL_RENAME, 1);
1134 err = ll_objects_destroy(request, old_dir);
1137 ptlrpc_req_finished(request);
1139 d_move(old_dentry, new_dentry);
1143 const struct inode_operations ll_dir_inode_operations = {
1145 .atomic_open = ll_atomic_open,
1146 .lookup = ll_lookup_nd,
1147 .create = ll_create_nd,
1148 /* We need all these non-raw things for NFSD, to not patch it. */
1149 .unlink = ll_unlink,
1152 .symlink = ll_symlink,
1154 .rename = ll_rename,
1155 .setattr = ll_setattr,
1156 .getattr = ll_getattr,
1157 .permission = ll_inode_permission,
1158 .setxattr = ll_setxattr,
1159 .getxattr = ll_getxattr,
1160 .listxattr = ll_listxattr,
1161 .removexattr = ll_removexattr,
1162 .get_acl = ll_get_acl,
1165 const struct inode_operations ll_special_inode_operations = {
1166 .setattr = ll_setattr,
1167 .getattr = ll_getattr,
1168 .permission = ll_inode_permission,
1169 .setxattr = ll_setxattr,
1170 .getxattr = ll_getxattr,
1171 .listxattr = ll_listxattr,
1172 .removexattr = ll_removexattr,
1173 .get_acl = ll_get_acl,