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, 2015, 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
87 " without object type: valid = %#llx\n",
88 PFID(&lli->lli_fid), body->valid);
92 inode->i_mode = (inode->i_mode & ~S_IFMT) | (body->mode & S_IFMT);
93 if (unlikely(inode->i_mode == 0)) {
94 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);
132 unlock_new_inode(inode);
133 } else if (!(inode->i_state & (I_FREEING | I_CLEAR)))
134 ll_update_inode(inode, md);
135 CDEBUG(D_VFSTRACE, "got inode: %p for "DFID"\n",
136 inode, PFID(&md->body->fid1));
141 static void ll_invalidate_negative_children(struct inode *dir)
143 struct dentry *dentry, *tmp_subdir;
146 hlist_for_each_entry(dentry, &dir->i_dentry, d_u.d_alias) {
147 spin_lock(&dentry->d_lock);
148 if (!list_empty(&dentry->d_subdirs)) {
149 struct dentry *child;
151 list_for_each_entry_safe(child, tmp_subdir,
154 if (d_really_is_negative(child))
155 d_lustre_invalidate(child, 1);
158 spin_unlock(&dentry->d_lock);
160 ll_unlock_dcache(dir);
163 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
164 void *data, int flag)
166 struct lustre_handle lockh;
170 case LDLM_CB_BLOCKING:
171 ldlm_lock2handle(lock, &lockh);
172 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
174 CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc);
178 case LDLM_CB_CANCELING: {
179 struct inode *inode = ll_inode_from_resource_lock(lock);
180 __u64 bits = lock->l_policy_data.l_inodebits.bits;
182 /* Inode is set to lock->l_resource->lr_lvb_inode
183 * for mdc - bug 24555 */
184 LASSERT(lock->l_ast_data == NULL);
189 /* Invalidate all dentries associated with this inode */
190 LASSERT(lock->l_flags & LDLM_FL_CANCELING);
192 if (!fid_res_name_eq(ll_inode2fid(inode),
193 &lock->l_resource->lr_name)) {
194 LDLM_ERROR(lock, "data mismatch with object "DFID"(%p)",
195 PFID(ll_inode2fid(inode)), inode);
199 if (bits & MDS_INODELOCK_XATTR) {
200 ll_xattr_cache_destroy(inode);
201 bits &= ~MDS_INODELOCK_XATTR;
204 /* For OPEN locks we differentiate between lock modes
205 * LCK_CR, LCK_CW, LCK_PR - bug 22891 */
206 if (bits & MDS_INODELOCK_OPEN)
207 ll_have_md_lock(inode, &bits, lock->l_req_mode);
209 if (bits & MDS_INODELOCK_OPEN) {
212 switch (lock->l_req_mode) {
223 LDLM_ERROR(lock, "bad lock mode for OPEN lock");
227 ll_md_real_close(inode, fmode);
230 if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
231 MDS_INODELOCK_LAYOUT | MDS_INODELOCK_PERM))
232 ll_have_md_lock(inode, &bits, LCK_MINMODE);
234 if (bits & MDS_INODELOCK_LAYOUT) {
235 struct cl_object_conf conf = {
236 .coc_opc = OBJECT_CONF_INVALIDATE,
240 rc = ll_layout_conf(inode, &conf);
242 CDEBUG(D_INODE, "cannot invalidate layout of "
244 PFID(ll_inode2fid(inode)), rc);
247 if (bits & MDS_INODELOCK_UPDATE) {
248 struct ll_inode_info *lli = ll_i2info(inode);
250 spin_lock(&lli->lli_lock);
251 lli->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
252 spin_unlock(&lli->lli_lock);
255 if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) {
256 CDEBUG(D_INODE, "invalidating inode %lu\n",
258 truncate_inode_pages(inode->i_mapping, 0);
259 ll_invalidate_negative_children(inode);
262 if ((bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM)) &&
263 inode->i_sb->s_root != NULL &&
264 !is_root_inode(inode))
265 ll_invalidate_aliases(inode);
277 __u32 ll_i2suppgid(struct inode *i)
279 if (in_group_p(i->i_gid))
280 return (__u32)from_kgid(&init_user_ns, i->i_gid);
285 /* Pack the required supplementary groups into the supplied groups array.
286 * If we don't need to use the groups from the target inode(s) then we
287 * instead pack one or more groups from the user's supplementary group
288 * array in case it might be useful. Not needed if doing an MDS-side upcall. */
289 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
296 LASSERT(suppgids != NULL);
298 suppgids[0] = ll_i2suppgid(i1);
301 suppgids[1] = ll_i2suppgid(i2);
306 for (i = 0; i < current_ngroups; i++) {
307 if (suppgids[0] == -1) {
308 if (current_groups[i] != suppgids[1])
309 suppgids[0] = current_groups[i];
312 if (suppgids[1] == -1) {
313 if (current_groups[i] != suppgids[0])
314 suppgids[1] = current_groups[i];
323 * try to reuse three types of dentry:
324 * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid
325 * by concurrent .revalidate).
326 * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may
327 * be cleared by others calling d_lustre_revalidate).
328 * 3. DISCONNECTED alias.
330 static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
332 struct dentry *alias, *discon_alias, *invalid_alias;
334 if (hlist_empty(&inode->i_dentry))
337 discon_alias = invalid_alias = NULL;
339 ll_lock_dcache(inode);
340 hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
341 LASSERT(alias != dentry);
343 spin_lock(&alias->d_lock);
344 if (alias->d_flags & DCACHE_DISCONNECTED)
345 /* LASSERT(last_discon == NULL); LU-405, bz 20055 */
346 discon_alias = alias;
347 else if (alias->d_parent == dentry->d_parent &&
348 alias->d_name.hash == dentry->d_name.hash &&
349 alias->d_name.len == dentry->d_name.len &&
350 memcmp(alias->d_name.name, dentry->d_name.name,
351 dentry->d_name.len) == 0)
352 invalid_alias = alias;
353 spin_unlock(&alias->d_lock);
358 alias = invalid_alias ?: discon_alias ?: NULL;
360 spin_lock(&alias->d_lock);
362 spin_unlock(&alias->d_lock);
364 ll_unlock_dcache(inode);
370 * Similar to d_splice_alias(), but lustre treats invalid alias
371 * similar to DCACHE_DISCONNECTED, and tries to use it anyway.
373 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de)
379 new = ll_find_alias(inode, de);
389 "Reuse dentry %p inode %p refc %d flags %#x\n",
390 new, d_inode(new), d_count(new), new->d_flags);
398 CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n",
399 de, d_inode(de), d_count(de), de->d_flags);
403 static int ll_lookup_it_finish(struct ptlrpc_request *request,
404 struct lookup_intent *it,
405 struct inode *parent, struct dentry **de)
407 struct inode *inode = NULL;
411 /* NB 1 request reference will be taken away by ll_intent_lock()
413 CDEBUG(D_DENTRY, "it %p it_disposition %x\n", it,
414 it->d.lustre.it_disposition);
415 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
416 rc = ll_prep_inode(&inode, request, (*de)->d_sb, it);
420 ll_set_lock_data(ll_i2sbi(parent)->ll_md_exp, inode, it, &bits);
422 /* We used to query real size from OSTs here, but actually
423 this is not needed. For stat() calls size would be updated
424 from subsequent do_revalidate()->ll_inode_revalidate_it() in
426 vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
427 Everybody else who needs correct file size would call
428 ll_glimpse_size or some equivalent themselves anyway.
429 Also see bug 7198. */
432 /* Only hash *de if it is unhashed (new dentry).
433 * Atoimc_open may passing hashed dentries for open.
435 if (d_unhashed(*de)) {
436 struct dentry *alias;
438 alias = ll_splice_alias(inode, *de);
444 } else if (!it_disposition(it, DISP_LOOKUP_NEG) &&
445 !it_disposition(it, DISP_OPEN_CREATE)) {
446 /* With DISP_OPEN_CREATE dentry will
447 instantiated in ll_create_it. */
448 LASSERT(d_inode(*de) == NULL);
449 d_instantiate(*de, inode);
452 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
453 /* we have lookup look - unhide dentry */
454 if (bits & MDS_INODELOCK_LOOKUP)
455 d_lustre_revalidate(*de);
456 } else if (!it_disposition(it, DISP_OPEN_CREATE)) {
457 /* If file created on server, don't depend on parent UPDATE
458 * lock to unhide it. It is left hidden and next lookup can
459 * find it in ll_splice_alias.
461 /* Check that parent has UPDATE lock. */
462 struct lookup_intent parent_it = {
464 .d.lustre.it_lock_handle = 0 };
466 if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it,
467 &ll_i2info(parent)->lli_fid, NULL)) {
468 d_lustre_revalidate(*de);
469 ll_intent_release(&parent_it);
474 if (rc != 0 && it->it_op & IT_OPEN)
475 ll_open_cleanup((*de)->d_sb, request);
480 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
481 struct lookup_intent *it, int lookup_flags)
483 struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
484 struct dentry *save = dentry, *retval;
485 struct ptlrpc_request *req = NULL;
487 struct md_op_data *op_data;
491 if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
492 return ERR_PTR(-ENAMETOOLONG);
494 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),intent=%s\n",
495 dentry, parent->i_ino,
496 parent->i_generation, parent, LL_IT2STR(it));
498 if (d_mountpoint(dentry))
499 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
501 if (it == NULL || it->it_op == IT_GETXATTR)
504 if (it->it_op == IT_GETATTR) {
505 rc = ll_statahead_enter(parent, &dentry, 0);
515 if (it->it_op & IT_CREAT)
516 opc = LUSTRE_OPC_CREATE;
518 opc = LUSTRE_OPC_ANY;
520 op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name,
521 dentry->d_name.len, lookup_flags, opc,
524 return (void *)op_data;
526 /* enforce umask if acl disabled or MDS doesn't support umask */
527 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
528 it->it_create_mode &= ~current_umask();
530 rc = md_intent_lock(ll_i2mdexp(parent), op_data, NULL, 0, it,
531 lookup_flags, &req, ll_md_blocking_ast, 0);
532 ll_finish_md_op_data(op_data);
534 retval = ERR_PTR(rc);
538 rc = ll_lookup_it_finish(req, it, parent, &dentry);
540 ll_intent_release(it);
541 retval = ERR_PTR(rc);
545 inode = d_inode(dentry);
546 if ((it->it_op & IT_OPEN) && inode &&
547 !S_ISREG(inode->i_mode) &&
548 !S_ISDIR(inode->i_mode)) {
549 ll_release_openhandle(inode, it);
551 ll_lookup_finish_locks(it, inode);
559 ptlrpc_req_finished(req);
560 if (it->it_op == IT_GETATTR && (retval == NULL || retval == dentry))
561 ll_statahead_mark(parent, dentry);
565 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
568 struct lookup_intent *itp, it = { .it_op = IT_GETATTR };
571 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),flags=%u\n",
572 dentry, parent->i_ino,
573 parent->i_generation, parent, flags);
575 /* Optimize away (CREATE && !OPEN). Let .create handle the race. */
576 if ((flags & LOOKUP_CREATE) && !(flags & LOOKUP_OPEN))
579 if (flags & (LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE))
583 de = ll_lookup_it(parent, dentry, itp, 0);
586 ll_intent_release(itp);
592 * For cached negative dentry and new dentry, handle lookup/create/open
595 static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
596 struct file *file, unsigned open_flags,
597 umode_t mode, int *opened)
599 struct lookup_intent *it;
601 long long lookup_flags = LOOKUP_OPEN;
605 "VFS Op:name=%pd,dir=%lu/%u(%p),file %p,open_flags %x,mode %x opened %d\n",
607 dir->i_generation, dir, file, open_flags, mode, *opened);
609 it = kzalloc(sizeof(*it), GFP_NOFS);
614 if (open_flags & O_CREAT) {
615 it->it_op |= IT_CREAT;
616 lookup_flags |= LOOKUP_CREATE;
618 it->it_create_mode = (mode & S_IALLUGO) | S_IFREG;
619 it->it_flags = (open_flags & ~O_ACCMODE) | OPEN_FMODE(open_flags);
621 /* Dentry added to dcache tree in ll_lookup_it */
622 de = ll_lookup_it(dir, dentry, it, lookup_flags);
629 if (it_disposition(it, DISP_OPEN_CREATE)) {
630 /* Dentry instantiated in ll_create_it. */
631 rc = ll_create_it(dir, dentry, mode, it);
633 /* We dget in ll_splice_alias. */
639 *opened |= FILE_CREATED;
641 if (d_really_is_positive(dentry) && it_disposition(it, DISP_OPEN_OPEN)) {
643 if (S_ISFIFO(d_inode(dentry)->i_mode)) {
644 /* We cannot call open here as it would
647 if (it_disposition(it, DISP_ENQ_OPEN_REF))
649 (struct ptlrpc_request *)
650 it->d.lustre.it_data);
651 rc = finish_no_open(file, de);
653 file->private_data = it;
654 rc = finish_open(file, dentry, NULL, opened);
655 /* We dget in ll_splice_alias. finish_open takes
656 * care of dget for fd open.
662 rc = finish_no_open(file, de);
667 ll_intent_release(it);
673 /* We depend on "mode" being set with the proper file type/umask by now */
674 static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
676 struct inode *inode = NULL;
677 struct ptlrpc_request *request = NULL;
678 struct ll_sb_info *sbi = ll_i2sbi(dir);
681 LASSERT(it && it->d.lustre.it_disposition);
683 LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
684 request = it->d.lustre.it_data;
685 it_clear_disposition(it, DISP_ENQ_CREATE_REF);
686 rc = ll_prep_inode(&inode, request, dir->i_sb, it);
692 LASSERT(hlist_empty(&inode->i_dentry));
694 /* We asked for a lock on the directory, but were granted a
695 * lock on the inode. Since we finally have an inode pointer,
696 * stuff it in the lock. */
697 CDEBUG(D_DLMTRACE, "setting l_ast_data to inode %p (%lu/%u)\n",
698 inode, inode->i_ino, inode->i_generation);
699 ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
701 ptlrpc_req_finished(request);
706 * By the time this is called, we already have created the directory cache
707 * entry for the new file, but it is so far negative - it has no inode.
709 * We defer creating the OBD object(s) until open, to keep the intent and
710 * non-intent code paths similar, and also because we do not have the MDS
711 * inode number before calling ll_create_node() (which is needed for LOV),
712 * so we would need to do yet another RPC to the MDS to store the LOV EA
713 * data on the MDS. If needed, we would pass the PACKED lmm as data and
714 * lmm_size in datalen (the MDS still has code which will handle that).
716 * If the create succeeds, we fill in the inode information
717 * with d_instantiate().
719 static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode,
720 struct lookup_intent *it)
725 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),intent=%s\n",
727 dir->i_generation, dir, LL_IT2STR(it));
729 rc = it_open_error(DISP_OPEN_CREATE, it);
733 inode = ll_create_node(dir, it);
735 return PTR_ERR(inode);
737 d_instantiate(dentry, inode);
741 static void ll_update_times(struct ptlrpc_request *request,
744 struct mdt_body *body = req_capsule_server_get(&request->rq_pill,
748 if (body->valid & OBD_MD_FLMTIME &&
749 body->mtime > LTIME_S(inode->i_mtime)) {
750 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %llu\n",
751 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
752 LTIME_S(inode->i_mtime) = body->mtime;
754 if (body->valid & OBD_MD_FLCTIME &&
755 body->ctime > LTIME_S(inode->i_ctime))
756 LTIME_S(inode->i_ctime) = body->ctime;
759 static int ll_new_node(struct inode *dir, struct dentry *dentry,
760 const char *tgt, int mode, int rdev,
763 struct ptlrpc_request *request = NULL;
764 struct md_op_data *op_data;
765 struct inode *inode = NULL;
766 struct ll_sb_info *sbi = ll_i2sbi(dir);
770 if (unlikely(tgt != NULL))
771 tgt_len = strlen(tgt) + 1;
773 op_data = ll_prep_md_op_data(NULL, dir, NULL,
777 if (IS_ERR(op_data)) {
778 err = PTR_ERR(op_data);
782 err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode,
783 from_kuid(&init_user_ns, current_fsuid()),
784 from_kgid(&init_user_ns, current_fsgid()),
785 cfs_curproc_cap_pack(), rdev, &request);
786 ll_finish_md_op_data(op_data);
790 ll_update_times(request, dir);
792 err = ll_prep_inode(&inode, request, dir->i_sb, NULL);
796 d_instantiate(dentry, inode);
798 ptlrpc_req_finished(request);
803 static int ll_mknod(struct inode *dir, struct dentry *dchild,
804 umode_t mode, dev_t rdev)
808 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p) mode %o dev %x\n",
809 dchild, dir->i_ino, dir->i_generation, dir,
810 mode, old_encode_dev(rdev));
812 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
813 mode &= ~current_umask();
815 switch (mode & S_IFMT) {
817 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
823 err = ll_new_node(dir, dchild, NULL, mode,
824 old_encode_dev(rdev),
835 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD, 1);
841 * Plain create. Intent create is handled in atomic_open.
843 static int ll_create_nd(struct inode *dir, struct dentry *dentry,
844 umode_t mode, bool want_excl)
848 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),flags=%u, excl=%d\n",
850 dir->i_generation, dir, mode, want_excl);
852 rc = ll_mknod(dir, dentry, mode, 0);
854 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
856 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, unhashed %d\n",
857 dentry, d_unhashed(dentry));
862 static inline void ll_get_child_fid(struct dentry *child, struct lu_fid *fid)
864 if (d_really_is_positive(child))
865 *fid = *ll_inode2fid(d_inode(child));
868 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
870 struct mdt_body *body;
871 struct lov_mds_md *eadata;
872 struct lov_stripe_md *lsm = NULL;
873 struct obd_trans_info oti = { 0 };
877 /* req is swabbed so this is safe */
878 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
879 if (!(body->valid & OBD_MD_FLEASIZE))
882 if (body->eadatasize == 0) {
883 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
888 /* The MDS sent back the EA because we unlinked the last reference
889 * to this file. Use this EA to unlink the objects on the OST.
890 * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
891 * check it is complete and sensible. */
892 eadata = req_capsule_server_sized_get(&request->rq_pill, &RMF_MDT_MD,
894 LASSERT(eadata != NULL);
896 rc = obd_unpackmd(ll_i2dtexp(dir), &lsm, eadata, body->eadatasize);
898 CERROR("obd_unpackmd: %d\n", rc);
901 LASSERT(rc >= sizeof(*lsm));
903 oa = kmem_cache_alloc(obdo_cachep, GFP_NOFS | __GFP_ZERO);
909 oa->o_oi = lsm->lsm_oi;
910 oa->o_mode = body->mode & S_IFMT;
911 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
913 if (body->valid & OBD_MD_FLCOOKIE) {
914 oa->o_valid |= OBD_MD_FLCOOKIE;
916 req_capsule_server_sized_get(&request->rq_pill,
918 sizeof(struct llog_cookie) *
919 lsm->lsm_stripe_count);
920 if (oti.oti_logcookies == NULL) {
921 oa->o_valid &= ~OBD_MD_FLCOOKIE;
922 body->valid &= ~OBD_MD_FLCOOKIE;
926 rc = obd_destroy(NULL, ll_i2dtexp(dir), oa, lsm, &oti,
929 CERROR("obd destroy objid "DOSTID" error %d\n",
930 POSTID(&lsm->lsm_oi), rc);
932 obd_free_memmd(ll_i2dtexp(dir), &lsm);
933 kmem_cache_free(obdo_cachep, oa);
938 /* ll_unlink() doesn't update the inode with the new link count.
939 * Instead, ll_ddelete() and ll_d_iput() will update it based upon if there
940 * is any lock existing. They will recycle dentries and inodes based upon locks
942 static int ll_unlink(struct inode *dir, struct dentry *dentry)
944 struct ptlrpc_request *request = NULL;
945 struct md_op_data *op_data;
948 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
949 dentry, dir->i_ino, dir->i_generation, dir);
951 op_data = ll_prep_md_op_data(NULL, dir, NULL,
954 0, LUSTRE_OPC_ANY, NULL);
956 return PTR_ERR(op_data);
958 ll_get_child_fid(dentry, &op_data->op_fid3);
959 op_data->op_fid2 = op_data->op_fid3;
960 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
961 ll_finish_md_op_data(op_data);
965 ll_update_times(request, dir);
966 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1);
968 rc = ll_objects_destroy(request, dir);
970 ptlrpc_req_finished(request);
974 static int ll_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
978 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
979 dentry, dir->i_ino, dir->i_generation, dir);
981 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
982 mode &= ~current_umask();
983 mode = (mode & (S_IRWXUGO|S_ISVTX)) | S_IFDIR;
984 err = ll_new_node(dir, dentry, NULL, mode, 0, LUSTRE_OPC_MKDIR);
987 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR, 1);
992 static int ll_rmdir(struct inode *dir, struct dentry *dentry)
994 struct ptlrpc_request *request = NULL;
995 struct md_op_data *op_data;
998 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
999 dentry, dir->i_ino, dir->i_generation, dir);
1001 op_data = ll_prep_md_op_data(NULL, dir, NULL,
1002 dentry->d_name.name,
1004 S_IFDIR, LUSTRE_OPC_ANY, NULL);
1005 if (IS_ERR(op_data))
1006 return PTR_ERR(op_data);
1008 ll_get_child_fid(dentry, &op_data->op_fid3);
1009 op_data->op_fid2 = op_data->op_fid3;
1010 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1011 ll_finish_md_op_data(op_data);
1013 ll_update_times(request, dir);
1014 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
1017 ptlrpc_req_finished(request);
1021 static int ll_symlink(struct inode *dir, struct dentry *dentry,
1022 const char *oldname)
1026 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),target=%.*s\n",
1027 dentry, dir->i_ino, dir->i_generation,
1028 dir, 3000, oldname);
1030 err = ll_new_node(dir, dentry, oldname, S_IFLNK | S_IRWXUGO,
1031 0, LUSTRE_OPC_SYMLINK);
1034 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK, 1);
1039 static int ll_link(struct dentry *old_dentry, struct inode *dir,
1040 struct dentry *new_dentry)
1042 struct inode *src = d_inode(old_dentry);
1043 struct ll_sb_info *sbi = ll_i2sbi(dir);
1044 struct ptlrpc_request *request = NULL;
1045 struct md_op_data *op_data;
1049 "VFS Op: inode=%lu/%u(%p), dir=%lu/%u(%p), target=%pd\n",
1050 src->i_ino, src->i_generation, src, dir->i_ino,
1051 dir->i_generation, dir, new_dentry);
1053 op_data = ll_prep_md_op_data(NULL, src, dir, new_dentry->d_name.name,
1054 new_dentry->d_name.len,
1055 0, LUSTRE_OPC_ANY, NULL);
1056 if (IS_ERR(op_data))
1057 return PTR_ERR(op_data);
1059 err = md_link(sbi->ll_md_exp, op_data, &request);
1060 ll_finish_md_op_data(op_data);
1064 ll_update_times(request, dir);
1065 ll_stats_ops_tally(sbi, LPROC_LL_LINK, 1);
1067 ptlrpc_req_finished(request);
1071 static int ll_rename(struct inode *old_dir, struct dentry *old_dentry,
1072 struct inode *new_dir, struct dentry *new_dentry)
1074 struct ptlrpc_request *request = NULL;
1075 struct ll_sb_info *sbi = ll_i2sbi(old_dir);
1076 struct md_op_data *op_data;
1080 "VFS Op:oldname=%pd,src_dir=%lu/%u(%p),newname=%pd,tgt_dir=%lu/%u(%p)\n",
1081 old_dentry, old_dir->i_ino, old_dir->i_generation, old_dir,
1082 new_dentry, new_dir->i_ino, new_dir->i_generation, new_dir);
1084 op_data = ll_prep_md_op_data(NULL, old_dir, new_dir, NULL, 0, 0,
1085 LUSTRE_OPC_ANY, NULL);
1086 if (IS_ERR(op_data))
1087 return PTR_ERR(op_data);
1089 ll_get_child_fid(old_dentry, &op_data->op_fid3);
1090 ll_get_child_fid(new_dentry, &op_data->op_fid4);
1091 err = md_rename(sbi->ll_md_exp, op_data,
1092 old_dentry->d_name.name,
1093 old_dentry->d_name.len,
1094 new_dentry->d_name.name,
1095 new_dentry->d_name.len, &request);
1096 ll_finish_md_op_data(op_data);
1098 ll_update_times(request, old_dir);
1099 ll_update_times(request, new_dir);
1100 ll_stats_ops_tally(sbi, LPROC_LL_RENAME, 1);
1101 err = ll_objects_destroy(request, old_dir);
1104 ptlrpc_req_finished(request);
1106 d_move(old_dentry, new_dentry);
1110 const struct inode_operations ll_dir_inode_operations = {
1112 .atomic_open = ll_atomic_open,
1113 .lookup = ll_lookup_nd,
1114 .create = ll_create_nd,
1115 /* We need all these non-raw things for NFSD, to not patch it. */
1116 .unlink = ll_unlink,
1119 .symlink = ll_symlink,
1121 .rename = ll_rename,
1122 .setattr = ll_setattr,
1123 .getattr = ll_getattr,
1124 .permission = ll_inode_permission,
1125 .setxattr = ll_setxattr,
1126 .getxattr = ll_getxattr,
1127 .listxattr = ll_listxattr,
1128 .removexattr = ll_removexattr,
1129 .get_acl = ll_get_acl,
1132 const struct inode_operations ll_special_inode_operations = {
1133 .setattr = ll_setattr,
1134 .getattr = ll_getattr,
1135 .permission = ll_inode_permission,
1136 .setxattr = ll_setxattr,
1137 .getxattr = ll_getxattr,
1138 .listxattr = ll_listxattr,
1139 .removexattr = ll_removexattr,
1140 .get_acl = ll_get_acl,