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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
34 #include <linux/sched.h>
36 #include <linux/quotaops.h>
37 #include <linux/highmem.h>
38 #include <linux/pagemap.h>
39 #include <linux/security.h>
40 #include <linux/user_namespace.h>
41 #ifdef HAVE_UIDGID_HEADER
42 # include <linux/uidgid.h>
45 #define DEBUG_SUBSYSTEM S_LLITE
47 #include <obd_support.h>
48 #include <lustre_fid.h>
49 #include <lustre_dlm.h>
50 #include "llite_internal.h"
52 static int ll_create_it(struct inode *dir, struct dentry *dentry,
53 struct lookup_intent *it,
54 void *secctx, __u32 secctxlen);
56 /* called from iget5_locked->find_inode() under inode_lock spinlock */
57 static int ll_test_inode(struct inode *inode, void *opaque)
59 struct ll_inode_info *lli = ll_i2info(inode);
60 struct lustre_md *md = opaque;
62 if (unlikely(!(md->body->mbo_valid & OBD_MD_FLID))) {
63 CERROR("MDS body missing FID\n");
67 if (!lu_fid_eq(&lli->lli_fid, &md->body->mbo_fid1))
73 static int ll_set_inode(struct inode *inode, void *opaque)
75 struct ll_inode_info *lli = ll_i2info(inode);
76 struct mdt_body *body = ((struct lustre_md *)opaque)->body;
78 if (unlikely(!(body->mbo_valid & OBD_MD_FLID))) {
79 CERROR("MDS body missing FID\n");
83 lli->lli_fid = body->mbo_fid1;
84 if (unlikely(!(body->mbo_valid & OBD_MD_FLTYPE))) {
85 CERROR("Can not initialize inode "DFID" without object type: "
87 PFID(&lli->lli_fid), body->mbo_valid);
91 inode->i_mode = (inode->i_mode & ~S_IFMT) | (body->mbo_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(@hash), which is already instantiated by
105 * the intent lookup).
107 struct inode *ll_iget(struct super_block *sb, ino_t hash,
108 struct lustre_md *md)
116 inode = iget5_locked(sb, hash, ll_test_inode, ll_set_inode, md);
118 RETURN(ERR_PTR(-ENOMEM));
120 if (inode->i_state & I_NEW) {
121 rc = ll_read_inode2(inode, md);
122 if (rc == 0 && S_ISREG(inode->i_mode) &&
123 ll_i2info(inode)->lli_clob == NULL)
124 rc = cl_file_inode_init(inode, md);
127 /* Let's clear directory lsm here, otherwise
128 * make_bad_inode() will reset the inode mode
129 * to regular, then ll_clear_inode will not
130 * be able to clear lsm_md */
131 if (S_ISDIR(inode->i_mode))
132 ll_dir_clear_lsm_md(inode);
133 make_bad_inode(inode);
134 unlock_new_inode(inode);
138 inode_has_no_xattr(inode);
139 unlock_new_inode(inode);
141 } else if (is_bad_inode(inode)) {
143 inode = ERR_PTR(-ESTALE);
144 } else if (!(inode->i_state & (I_FREEING | I_CLEAR))) {
145 rc = ll_update_inode(inode, md);
146 CDEBUG(D_VFSTRACE, "got inode: "DFID"(%p): rc = %d\n",
147 PFID(&md->body->mbo_fid1), inode, rc);
149 if (S_ISDIR(inode->i_mode))
150 ll_dir_clear_lsm_md(inode);
159 static void ll_invalidate_negative_children(struct inode *dir)
161 struct dentry *dentry, *tmp_subdir;
162 DECLARE_LL_D_HLIST_NODE_PTR(p);
164 spin_lock(&dir->i_lock);
165 ll_d_hlist_for_each_entry(dentry, p, &dir->i_dentry) {
166 spin_lock(&dentry->d_lock);
167 if (!list_empty(&dentry->d_subdirs)) {
168 struct dentry *child;
170 list_for_each_entry_safe(child, tmp_subdir,
173 if (child->d_inode == NULL)
174 d_lustre_invalidate(child, 1);
177 spin_unlock(&dentry->d_lock);
179 spin_unlock(&dir->i_lock);
182 int ll_test_inode_by_fid(struct inode *inode, void *opaque)
184 return lu_fid_eq(&ll_i2info(inode)->lli_fid, opaque);
187 static int ll_dom_lock_cancel(struct inode *inode, struct ldlm_lock *lock)
190 struct ll_inode_info *lli = ll_i2info(inode);
195 if (!lli->lli_clob) {
196 /* due to DoM read on open, there may exist pages for Lustre
197 * regular file even though cl_object is not set up yet. */
198 truncate_inode_pages(inode->i_mapping, 0);
202 env = cl_env_get(&refcheck);
204 RETURN(PTR_ERR(env));
206 /* reach MDC layer to flush data under the DoM ldlm lock */
207 rc = cl_object_flush(env, lli->lli_clob, lock);
209 cl_env_put(env, &refcheck);
213 static void ll_lock_cancel_bits(struct ldlm_lock *lock, __u64 to_cancel)
215 struct inode *inode = ll_inode_from_resource_lock(lock);
216 struct ll_inode_info *lli;
217 __u64 bits = to_cancel;
223 /* That means the inode is evicted most likely and may cause
224 * the skipping of lock cleanups below, so print the message
227 if (lock->l_resource->lr_lvb_inode)
229 "can't take inode for the lock (%sevicted)\n",
230 lock->l_resource->lr_lvb_inode->i_state &
231 I_FREEING ? "" : "not ");
235 if (!fid_res_name_eq(ll_inode2fid(inode),
236 &lock->l_resource->lr_name)) {
237 LDLM_ERROR(lock, "data mismatch with object "DFID"(%p)",
238 PFID(ll_inode2fid(inode)), inode);
242 if (bits & MDS_INODELOCK_XATTR) {
243 ll_xattr_cache_destroy(inode);
244 bits &= ~MDS_INODELOCK_XATTR;
247 /* For OPEN locks we differentiate between lock modes
248 * LCK_CR, LCK_CW, LCK_PR - bug 22891 */
249 if (bits & MDS_INODELOCK_OPEN)
250 ll_have_md_lock(inode, &bits, lock->l_req_mode);
252 if (bits & MDS_INODELOCK_OPEN) {
255 switch (lock->l_req_mode) {
266 LDLM_ERROR(lock, "bad lock mode for OPEN lock");
270 ll_md_real_close(inode, fmode);
272 bits &= ~MDS_INODELOCK_OPEN;
275 if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
276 MDS_INODELOCK_LAYOUT | MDS_INODELOCK_PERM |
278 ll_have_md_lock(inode, &bits, LCK_MINMODE);
280 if (bits & MDS_INODELOCK_DOM) {
281 rc = ll_dom_lock_cancel(inode, lock);
283 CDEBUG(D_INODE, "cannot flush DoM data "
285 PFID(ll_inode2fid(inode)), rc);
286 lock_res_and_lock(lock);
287 ldlm_set_kms_ignore(lock);
288 unlock_res_and_lock(lock);
291 if (bits & MDS_INODELOCK_LAYOUT) {
292 struct cl_object_conf conf = {
293 .coc_opc = OBJECT_CONF_INVALIDATE,
297 rc = ll_layout_conf(inode, &conf);
299 CDEBUG(D_INODE, "cannot invalidate layout of "
301 PFID(ll_inode2fid(inode)), rc);
304 lli = ll_i2info(inode);
306 if (bits & MDS_INODELOCK_UPDATE)
307 lli->lli_update_atime = 1;
309 if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) {
310 CDEBUG(D_INODE, "invalidating inode "DFID" lli = %p, "
311 "pfid = "DFID"\n", PFID(ll_inode2fid(inode)),
312 lli, PFID(&lli->lli_pfid));
313 truncate_inode_pages(inode->i_mapping, 0);
315 if (unlikely(!fid_is_zero(&lli->lli_pfid))) {
316 struct inode *master_inode = NULL;
319 /* This is slave inode, since all of the child dentry
320 * is connected on the master inode, so we have to
321 * invalidate the negative children on master inode */
322 CDEBUG(D_INODE, "Invalidate s"DFID" m"DFID"\n",
323 PFID(ll_inode2fid(inode)), PFID(&lli->lli_pfid));
325 hash = cl_fid_build_ino(&lli->lli_pfid,
326 ll_need_32bit_api(ll_i2sbi(inode)));
328 /* Do not lookup the inode with ilookup5, otherwise
329 * it will cause dead lock,
330 * 1. Client1 send chmod req to the MDT0, then on MDT0,
331 * it enqueues master and all of its slaves lock,
332 * (mdt_attr_set() -> mdt_lock_slaves()), after gets
333 * master and stripe0 lock, it will send the enqueue
334 * req (for stripe1) to MDT1, then MDT1 finds the lock
335 * has been granted to client2. Then MDT1 sends blocking
337 * 2. At the same time, client2 tries to unlink
338 * the striped dir (rm -rf striped_dir), and during
339 * lookup, it will hold the master inode of the striped
340 * directory, whose inode state is NEW, then tries to
341 * revalidate all of its slaves, (ll_prep_inode()->
342 * ll_iget()->ll_read_inode2()-> ll_update_inode().).
343 * And it will be blocked on the server side because
345 * 3. Then the client get the blocking_ast req, cancel
346 * the lock, but being blocked if using ->ilookup5()),
347 * because master inode state is NEW. */
348 master_inode = ilookup5_nowait(inode->i_sb, hash,
349 ll_test_inode_by_fid,
350 (void *)&lli->lli_pfid);
352 ll_invalidate_negative_children(master_inode);
356 ll_invalidate_negative_children(inode);
360 if ((bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM)) &&
361 inode->i_sb->s_root != NULL &&
362 inode != inode->i_sb->s_root->d_inode)
363 ll_invalidate_aliases(inode);
365 if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM))
366 forget_all_cached_acls(inode);
372 /* Check if the given lock may be downgraded instead of canceling and
373 * that convert is really needed. */
374 int ll_md_need_convert(struct ldlm_lock *lock)
376 struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
378 __u64 wanted = lock->l_policy_data.l_inodebits.cancel_bits;
379 __u64 bits = lock->l_policy_data.l_inodebits.bits & ~wanted;
380 enum ldlm_mode mode = LCK_MINMODE;
382 if (!lock->l_conn_export ||
383 !exp_connect_lock_convert(lock->l_conn_export))
386 if (!wanted || !bits || ldlm_is_cancel(lock))
389 /* do not convert locks other than DOM for now */
390 if (!((bits | wanted) & MDS_INODELOCK_DOM))
393 /* We may have already remaining bits in some other lock so
394 * lock convert will leave us just extra lock for the same bit.
395 * Check if client has other lock with the same bits and the same
396 * or lower mode and don't convert if any.
398 switch (lock->l_req_mode) {
410 /* do not convert other modes */
414 /* is lock is too old to be converted? */
415 lock_res_and_lock(lock);
416 if (ktime_after(ktime_get(),
417 ktime_add(lock->l_last_used,
418 ktime_set(ns->ns_dirty_age_limit, 0)))) {
419 unlock_res_and_lock(lock);
422 unlock_res_and_lock(lock);
424 inode = ll_inode_from_resource_lock(lock);
425 ll_have_md_lock(inode, &bits, mode);
430 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
431 void *data, int flag)
433 struct lustre_handle lockh;
434 __u64 bits = lock->l_policy_data.l_inodebits.bits;
440 case LDLM_CB_BLOCKING:
442 __u64 cancel_flags = LCF_ASYNC;
444 if (ll_md_need_convert(lock)) {
445 cancel_flags |= LCF_CONVERT;
446 /* For lock convert some cancel actions may require
447 * this lock with non-dropped canceled bits, e.g. page
448 * flush for DOM lock. So call ll_lock_cancel_bits()
449 * here while canceled bits are still set.
451 bits = lock->l_policy_data.l_inodebits.cancel_bits;
452 if (bits & MDS_INODELOCK_DOM)
453 ll_lock_cancel_bits(lock, MDS_INODELOCK_DOM);
455 ldlm_lock2handle(lock, &lockh);
456 rc = ldlm_cli_cancel(&lockh, cancel_flags);
458 CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc);
463 case LDLM_CB_CANCELING:
464 /* Nothing to do for non-granted locks */
465 if (!ldlm_is_granted(lock))
468 if (ldlm_is_converting(lock)) {
469 /* this is called on already converted lock, so
470 * ibits has remained bits only and cancel_bits
471 * are bits that were dropped.
472 * Note that DOM lock is handled prior lock convert
473 * and is excluded here.
475 bits = lock->l_policy_data.l_inodebits.cancel_bits &
478 LASSERT(ldlm_is_canceling(lock));
480 ll_lock_cancel_bits(lock, bits);
489 __u32 ll_i2suppgid(struct inode *i)
491 if (in_group_p(i->i_gid))
492 return (__u32)from_kgid(&init_user_ns, i->i_gid);
494 return (__u32) __kgid_val(INVALID_GID);
497 /* Pack the required supplementary groups into the supplied groups array.
498 * If we don't need to use the groups from the target inode(s) then we
499 * instead pack one or more groups from the user's supplementary group
500 * array in case it might be useful. Not needed if doing an MDS-side upcall. */
501 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
504 LASSERT(suppgids != NULL);
506 suppgids[0] = ll_i2suppgid(i1);
509 suppgids[1] = ll_i2suppgid(i2);
515 * try to reuse three types of dentry:
516 * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid
517 * by concurrent .revalidate).
518 * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may
519 * be cleared by others calling d_lustre_revalidate).
520 * 3. DISCONNECTED alias.
522 static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
524 struct dentry *alias, *discon_alias, *invalid_alias;
525 DECLARE_LL_D_HLIST_NODE_PTR(p);
527 if (ll_d_hlist_empty(&inode->i_dentry))
530 discon_alias = invalid_alias = NULL;
532 spin_lock(&inode->i_lock);
533 ll_d_hlist_for_each_entry(alias, p, &inode->i_dentry) {
534 LASSERT(alias != dentry);
536 spin_lock(&alias->d_lock);
537 if ((alias->d_flags & DCACHE_DISCONNECTED) &&
538 S_ISDIR(inode->i_mode))
539 /* LASSERT(last_discon == NULL); LU-405, bz 20055 */
540 discon_alias = alias;
541 else if (alias->d_parent == dentry->d_parent &&
542 alias->d_name.hash == dentry->d_name.hash &&
543 alias->d_name.len == dentry->d_name.len &&
544 memcmp(alias->d_name.name, dentry->d_name.name,
545 dentry->d_name.len) == 0)
546 invalid_alias = alias;
547 spin_unlock(&alias->d_lock);
552 alias = invalid_alias ?: discon_alias ?: NULL;
554 spin_lock(&alias->d_lock);
556 spin_unlock(&alias->d_lock);
558 spin_unlock(&inode->i_lock);
564 * Similar to d_splice_alias(), but lustre treats invalid alias
565 * similar to DCACHE_DISCONNECTED, and tries to use it anyway.
567 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de)
573 new = ll_find_alias(inode, de);
583 "Reuse dentry %p inode %p refc %d flags %#x\n",
584 new, new->d_inode, ll_d_count(new), new->d_flags);
592 CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n",
593 de, de->d_inode, ll_d_count(de), de->d_flags);
597 static int ll_lookup_it_finish(struct ptlrpc_request *request,
598 struct lookup_intent *it,
599 struct inode *parent, struct dentry **de,
600 void *secctx, __u32 secctxlen)
602 struct inode *inode = NULL;
605 struct dentry *alias;
608 /* NB 1 request reference will be taken away by ll_intent_lock()
610 CDEBUG(D_DENTRY, "it %p it_disposition %x\n", it,
612 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
613 struct req_capsule *pill = &request->rq_pill;
614 struct mdt_body *body = req_capsule_server_get(pill,
617 rc = ll_prep_inode(&inode, request, (*de)->d_sb, it);
621 if (it->it_op & IT_OPEN)
622 ll_dom_finish_open(inode, request, it);
624 ll_set_lock_data(ll_i2sbi(parent)->ll_md_exp, inode, it, &bits);
626 /* We used to query real size from OSTs here, but actually
627 * this is not needed. For stat() calls size would be updated
628 * from subsequent do_revalidate()->ll_inode_revalidate_it() in
630 * vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
631 * Everybody else who needs correct file size would call
632 * ll_glimpse_size or some equivalent themselves anyway.
636 /* If security context was returned by MDT, put it in
637 * inode now to save an extra getxattr from security hooks,
638 * and avoid deadlock.
640 if (body->mbo_valid & OBD_MD_SECCTX) {
641 secctx = req_capsule_server_get(pill, &RMF_FILE_SECCTX);
642 secctxlen = req_capsule_get_size(pill,
647 CDEBUG(D_SEC, "server returned security context"
649 PFID(ll_inode2fid(inode)));
652 if (secctx != NULL && secctxlen != 0) {
654 rc = security_inode_notifysecctx(inode, secctx,
658 CWARN("cannot set security context for "
660 PFID(ll_inode2fid(inode)), rc);
664 /* Only hash *de if it is unhashed (new dentry).
665 * Atoimc_open may passin hashed dentries for open.
667 alias = ll_splice_alias(inode, *de);
669 GOTO(out, rc = PTR_ERR(alias));
673 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
674 /* we have lookup look - unhide dentry */
675 if (bits & MDS_INODELOCK_LOOKUP)
676 d_lustre_revalidate(*de);
677 } else if (!it_disposition(it, DISP_OPEN_CREATE)) {
679 * If file was created on the server, the dentry is revalidated
680 * in ll_create_it if the lock allows for it.
682 /* Check that parent has UPDATE lock. */
683 struct lookup_intent parent_it = {
685 .it_lock_handle = 0 };
686 struct lu_fid fid = ll_i2info(parent)->lli_fid;
688 /* If it is striped directory, get the real stripe parent */
689 if (unlikely(ll_dir_striped(parent))) {
690 rc = md_get_fid_from_lsm(ll_i2mdexp(parent),
691 ll_i2info(parent)->lli_lsm_md,
693 (*de)->d_name.len, &fid);
698 if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it, &fid,
700 d_lustre_revalidate(*de);
701 ll_intent_release(&parent_it);
708 if (rc != 0 && it->it_op & IT_OPEN)
709 ll_open_cleanup((*de)->d_sb, request);
714 struct pcc_create_attach {
715 struct pcc_dataset *pca_dataset;
716 struct dentry *pca_dentry;
719 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
720 struct lookup_intent *it,
721 void **secctx, __u32 *secctxlen,
722 struct pcc_create_attach *pca)
724 struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
725 struct dentry *save = dentry, *retval;
726 struct ptlrpc_request *req = NULL;
727 struct md_op_data *op_data = NULL;
728 struct lov_user_md *lum = NULL;
731 char secctx_name[XATTR_NAME_MAX + 1];
735 if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
736 RETURN(ERR_PTR(-ENAMETOOLONG));
738 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), intent=%s\n",
739 dentry->d_name.len, dentry->d_name.name,
740 PFID(ll_inode2fid(parent)), parent, LL_IT2STR(it));
742 if (d_mountpoint(dentry))
743 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
745 if (it == NULL || it->it_op == IT_GETXATTR)
748 if (it->it_op == IT_GETATTR && dentry_may_statahead(parent, dentry)) {
749 rc = ll_statahead(parent, &dentry, 0);
751 RETURN(dentry == save ? NULL : dentry);
754 if (it->it_op & IT_OPEN && it->it_flags & FMODE_WRITE &&
755 dentry->d_sb->s_flags & SB_RDONLY)
756 RETURN(ERR_PTR(-EROFS));
758 if (it->it_op & IT_CREAT)
759 opc = LUSTRE_OPC_CREATE;
761 opc = LUSTRE_OPC_ANY;
763 op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name,
764 dentry->d_name.len, 0, opc, NULL);
766 GOTO(out, retval = ERR_CAST(op_data));
768 /* enforce umask if acl disabled or MDS doesn't support umask */
769 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
770 it->it_create_mode &= ~current_umask();
772 if (it->it_op & IT_CREAT &&
773 ll_i2sbi(parent)->ll_flags & LL_SBI_FILE_SECCTX) {
774 rc = ll_dentry_init_security(dentry, it->it_create_mode,
776 &op_data->op_file_secctx_name,
777 &op_data->op_file_secctx,
778 &op_data->op_file_secctx_size);
780 GOTO(out, retval = ERR_PTR(rc));
782 *secctx = op_data->op_file_secctx;
783 if (secctxlen != NULL)
784 *secctxlen = op_data->op_file_secctx_size;
788 if (secctxlen != NULL)
792 /* ask for security context upon intent */
793 if (it->it_op & (IT_LOOKUP | IT_GETATTR | IT_OPEN)) {
794 /* get name of security xattr to request to server */
795 rc = ll_listsecurity(parent, secctx_name,
796 sizeof(secctx_name));
798 CDEBUG(D_SEC, "cannot get security xattr name for "
800 PFID(ll_inode2fid(parent)), rc);
802 op_data->op_file_secctx_name = secctx_name;
803 op_data->op_file_secctx_name_size = rc;
804 CDEBUG(D_SEC, "'%.*s' is security xattr for "DFID"\n",
805 rc, secctx_name, PFID(ll_inode2fid(parent)));
809 if (pca && pca->pca_dataset) {
810 struct pcc_dataset *dataset = pca->pca_dataset;
814 GOTO(out, retval = ERR_PTR(-ENOMEM));
816 lum->lmm_magic = LOV_USER_MAGIC_V1;
817 lum->lmm_pattern = LOV_PATTERN_F_RELEASED | LOV_PATTERN_RAID0;
818 op_data->op_data = lum;
819 op_data->op_data_size = sizeof(*lum);
820 op_data->op_archive_id = dataset->pccd_rwid;
822 rc = obd_fid_alloc(NULL, ll_i2mdexp(parent), &op_data->op_fid2,
825 GOTO(out, retval = ERR_PTR(rc));
827 rc = pcc_inode_create(parent->i_sb, dataset, &op_data->op_fid2,
830 GOTO(out, retval = ERR_PTR(rc));
832 it->it_flags |= MDS_OPEN_PCC;
835 rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
836 &ll_md_blocking_ast, 0);
837 /* If the MDS allows the client to chgrp (CFS_SETGRP_PERM), but the
838 * client does not know which suppgid should be sent to the MDS, or
839 * some other(s) changed the target file's GID after this RPC sent
840 * to the MDS with the suppgid as the original GID, then we should
841 * try again with right suppgid. */
842 if (rc == -EACCES && it->it_op & IT_OPEN &&
843 it_disposition(it, DISP_OPEN_DENY)) {
844 struct mdt_body *body;
846 LASSERT(req != NULL);
848 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
849 if (op_data->op_suppgids[0] == body->mbo_gid ||
850 op_data->op_suppgids[1] == body->mbo_gid ||
851 !in_group_p(make_kgid(&init_user_ns, body->mbo_gid)))
852 GOTO(out, retval = ERR_PTR(-EACCES));
854 fid_zero(&op_data->op_fid2);
855 op_data->op_suppgids[1] = body->mbo_gid;
856 ptlrpc_req_finished(req);
858 ll_intent_release(it);
859 rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
860 &ll_md_blocking_ast, 0);
864 GOTO(out, retval = ERR_PTR(rc));
866 /* dir layout may change */
867 ll_unlock_md_op_lsm(op_data);
868 rc = ll_lookup_it_finish(req, it, parent, &dentry,
869 secctx != NULL ? *secctx : NULL,
870 secctxlen != NULL ? *secctxlen : 0);
872 ll_intent_release(it);
873 GOTO(out, retval = ERR_PTR(rc));
876 if ((it->it_op & IT_OPEN) && dentry->d_inode &&
877 !S_ISREG(dentry->d_inode->i_mode) &&
878 !S_ISDIR(dentry->d_inode->i_mode)) {
879 ll_release_openhandle(dentry, it);
881 ll_lookup_finish_locks(it, dentry);
883 GOTO(out, retval = (dentry == save) ? NULL : dentry);
886 if (op_data != NULL && !IS_ERR(op_data)) {
887 if (secctx != NULL && secctxlen != NULL) {
888 /* caller needs sec ctx info, so reset it in op_data to
889 * prevent it from being freed */
890 op_data->op_file_secctx = NULL;
891 op_data->op_file_secctx_size = 0;
893 ll_finish_md_op_data(op_data);
899 ptlrpc_req_finished(req);
903 #ifdef HAVE_IOP_ATOMIC_OPEN
904 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
907 struct lookup_intent *itp, it = { .it_op = IT_GETATTR };
910 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), flags=%u\n",
911 dentry->d_name.len, dentry->d_name.name,
912 PFID(ll_inode2fid(parent)), parent, flags);
915 * Optimize away (CREATE && !OPEN). Let .create handle the race.
916 * but only if we have write permissions there, otherwise we need
917 * to proceed with lookup. LU-4185
919 if ((flags & LOOKUP_CREATE) && !(flags & LOOKUP_OPEN) &&
920 (inode_permission(parent, MAY_WRITE | MAY_EXEC) == 0))
923 if (flags & (LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE))
927 de = ll_lookup_it(parent, dentry, itp, NULL, NULL, NULL);
930 ll_intent_release(itp);
935 #ifdef FMODE_CREATED /* added in Linux v4.18-rc1-20-g73a09dd */
936 # define ll_is_opened(o, f) ((f)->f_mode & FMODE_OPENED)
937 # define ll_finish_open(f, d, o) finish_open((f), (d), NULL)
939 # define ll_set_created(o, f) \
941 (f)->f_mode |= FMODE_CREATED; \
945 # define ll_is_opened(o, f) (*(o))
946 # define ll_finish_open(f, d, o) finish_open((f), (d), NULL, (o))
947 # define ll_last_arg , int *opened
948 # define ll_set_created(o, f) \
950 *(o) |= FILE_CREATED; \
956 * For cached negative dentry and new dentry, handle lookup/create/open
959 static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
960 struct file *file, unsigned open_flags,
961 umode_t mode ll_last_arg)
963 struct lookup_intent *it;
965 long long lookup_flags = LOOKUP_OPEN;
968 struct ll_sb_info *sbi;
969 struct pcc_create_attach pca = {NULL, NULL};
970 struct pcc_dataset *dataset = NULL;
974 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), file %p,"
975 "open_flags %x, mode %x opened %d\n",
976 dentry->d_name.len, dentry->d_name.name,
977 PFID(ll_inode2fid(dir)), dir, file, open_flags, mode,
978 ll_is_opened(opened, file));
980 /* Only negative dentries enter here */
981 LASSERT(dentry->d_inode == NULL);
983 if (!d_unhashed(dentry)) {
984 /* A valid negative dentry that just passed revalidation,
985 * there's little point to try and open it server-side,
986 * even though there's a minuscule chance it might succeed.
987 * Either way it's a valid race to just return -ENOENT here.
989 if (!(open_flags & O_CREAT))
992 /* Otherwise we just unhash it to be rehashed afresh via
993 * lookup if necessary
998 OBD_ALLOC(it, sizeof(*it));
1002 it->it_op = IT_OPEN;
1003 if (open_flags & O_CREAT) {
1004 it->it_op |= IT_CREAT;
1005 lookup_flags |= LOOKUP_CREATE;
1006 sbi = ll_i2sbi(dir);
1007 /* Volatile file is used for HSM restore, so do not use PCC */
1008 if (!filename_is_volatile(dentry->d_name.name,
1009 dentry->d_name.len, NULL)) {
1010 struct pcc_matcher item;
1012 item.pm_uid = from_kuid(&init_user_ns, current_uid());
1013 item.pm_gid = from_kgid(&init_user_ns, current_gid());
1014 item.pm_projid = ll_i2info(dir)->lli_projid;
1015 item.pm_name = &dentry->d_name;
1016 dataset = pcc_dataset_match_get(&sbi->ll_pcc_super,
1018 pca.pca_dataset = dataset;
1021 it->it_create_mode = (mode & S_IALLUGO) | S_IFREG;
1022 it->it_flags = (open_flags & ~O_ACCMODE) | OPEN_FMODE(open_flags);
1023 it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
1025 /* Dentry added to dcache tree in ll_lookup_it */
1026 de = ll_lookup_it(dir, dentry, it, &secctx, &secctxlen, &pca);
1029 else if (de != NULL)
1032 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1035 if (it_disposition(it, DISP_OPEN_CREATE)) {
1036 /* Dentry instantiated in ll_create_it. */
1037 rc = ll_create_it(dir, dentry, it, secctx, secctxlen);
1038 security_release_secctx(secctx, secctxlen);
1040 /* We dget in ll_splice_alias. */
1045 if (dataset != NULL && dentry->d_inode) {
1046 rc = pcc_inode_create_fini(dataset,
1052 GOTO(out_release, rc);
1055 ll_set_created(opened, file);
1058 if (dentry->d_inode && it_disposition(it, DISP_OPEN_OPEN)) {
1060 if (S_ISFIFO(dentry->d_inode->i_mode)) {
1061 /* We cannot call open here as it might
1062 * deadlock. This case is unreachable in
1063 * practice because of OBD_CONNECT_NODEVOH. */
1064 rc = finish_no_open(file, de);
1066 file->private_data = it;
1067 rc = ll_finish_open(file, dentry, opened);
1068 /* We dget in ll_splice_alias. finish_open takes
1069 * care of dget for fd open.
1075 rc = finish_no_open(file, de);
1080 if (dataset != NULL)
1081 pcc_dataset_put(dataset);
1082 ll_intent_release(it);
1083 OBD_FREE(it, sizeof(*it));
1088 #else /* !HAVE_IOP_ATOMIC_OPEN */
1089 static struct lookup_intent *
1090 ll_convert_intent(struct open_intent *oit, int lookup_flags, bool is_readonly)
1092 struct lookup_intent *it;
1096 return ERR_PTR(-ENOMEM);
1098 if (lookup_flags & LOOKUP_OPEN) {
1099 it->it_op = IT_OPEN;
1100 /* Avoid file creation for ro bind mount point(is_readonly) */
1101 if ((lookup_flags & LOOKUP_CREATE) && !is_readonly)
1102 it->it_op |= IT_CREAT;
1103 it->it_create_mode = (oit->create_mode & S_IALLUGO) | S_IFREG;
1104 it->it_flags = ll_namei_to_lookup_intent_flag(oit->flags &
1105 ~(is_readonly ? O_CREAT : 0));
1106 it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
1108 it->it_op = IT_GETATTR;
1114 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
1115 struct nameidata *nd)
1120 if (nd && !(nd->flags & (LOOKUP_CONTINUE|LOOKUP_PARENT))) {
1121 struct lookup_intent *it;
1123 if (ll_d2d(dentry) && ll_d2d(dentry)->lld_it) {
1124 it = ll_d2d(dentry)->lld_it;
1125 ll_d2d(dentry)->lld_it = NULL;
1128 * Optimize away (CREATE && !OPEN). Let .create handle
1129 * the race. But only if we have write permissions
1130 * there, otherwise we need to proceed with lookup.
1133 if ((nd->flags & LOOKUP_CREATE) &&
1134 !(nd->flags & LOOKUP_OPEN) &&
1135 (inode_permission(parent,
1136 MAY_WRITE | MAY_EXEC) == 0))
1139 it = ll_convert_intent(&nd->intent.open, nd->flags,
1140 (nd->path.mnt->mnt_flags & MNT_READONLY) ||
1141 (nd->path.mnt->mnt_sb->s_flags & SB_RDONLY));
1143 RETURN((struct dentry *)it);
1146 de = ll_lookup_it(parent, dentry, it, NULL, NULL, NULL);
1149 if ((nd->flags & LOOKUP_OPEN) && !IS_ERR(dentry)) { /* Open */
1150 if (dentry->d_inode &&
1151 it_disposition(it, DISP_OPEN_OPEN)) { /* nocreate */
1152 if (S_ISFIFO(dentry->d_inode->i_mode)) {
1153 /* We cannot call open here as it might
1154 * deadlock. This case is unreachable in
1155 * practice because of
1156 * OBD_CONNECT_NODEVOH. */
1160 nd->intent.open.file->private_data = it;
1161 filp = lookup_instantiate_filp(nd,
1167 de = (struct dentry *)filp;
1170 } else if (it_disposition(it, DISP_OPEN_CREATE)) {
1171 /* XXX This can only reliably work on assumption
1172 * that there are NO hashed negative dentries.*/
1173 ll_d2d(dentry)->lld_it = it;
1174 it = NULL; /* Will be freed in ll_create_nd */
1175 /* We absolutely depend on ll_create_nd to be
1176 * called to not leak this intent and possible
1177 * data attached to it */
1182 ll_intent_release(it);
1183 OBD_FREE(it, sizeof(*it));
1186 de = ll_lookup_it(parent, dentry, NULL, NULL, NULL, NULL);
1191 #endif /* HAVE_IOP_ATOMIC_OPEN */
1193 /* We depend on "mode" being set with the proper file type/umask by now */
1194 static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
1196 struct inode *inode = NULL;
1197 struct ptlrpc_request *request = NULL;
1198 struct ll_sb_info *sbi = ll_i2sbi(dir);
1202 LASSERT(it && it->it_disposition);
1204 LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
1205 request = it->it_request;
1206 it_clear_disposition(it, DISP_ENQ_CREATE_REF);
1207 rc = ll_prep_inode(&inode, request, dir->i_sb, it);
1209 GOTO(out, inode = ERR_PTR(rc));
1211 /* Pause to allow for a race with concurrent access by fid */
1212 OBD_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_NODE_PAUSE, cfs_fail_val);
1214 /* We asked for a lock on the directory, but were granted a
1215 * lock on the inode. Since we finally have an inode pointer,
1216 * stuff it in the lock. */
1217 CDEBUG(D_DLMTRACE, "setting l_ast_data to inode "DFID"(%p)\n",
1218 PFID(ll_inode2fid(inode)), inode);
1219 ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
1222 ptlrpc_req_finished(request);
1227 * By the time this is called, we already have created the directory cache
1228 * entry for the new file, but it is so far negative - it has no inode.
1230 * We defer creating the OBD object(s) until open, to keep the intent and
1231 * non-intent code paths similar, and also because we do not have the MDS
1232 * inode number before calling ll_create_node() (which is needed for LOV),
1233 * so we would need to do yet another RPC to the MDS to store the LOV EA
1234 * data on the MDS. If needed, we would pass the PACKED lmm as data and
1235 * lmm_size in datalen (the MDS still has code which will handle that).
1237 * If the create succeeds, we fill in the inode information
1238 * with d_instantiate().
1240 static int ll_create_it(struct inode *dir, struct dentry *dentry,
1241 struct lookup_intent *it,
1242 void *secctx, __u32 secctxlen)
1244 struct inode *inode;
1249 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), intent=%s\n",
1250 dentry->d_name.len, dentry->d_name.name,
1251 PFID(ll_inode2fid(dir)), dir, LL_IT2STR(it));
1253 rc = it_open_error(DISP_OPEN_CREATE, it);
1257 inode = ll_create_node(dir, it);
1259 RETURN(PTR_ERR(inode));
1261 if ((ll_i2sbi(inode)->ll_flags & LL_SBI_FILE_SECCTX) &&
1264 /* must be done before d_instantiate, because it calls
1265 * security_d_instantiate, which means a getxattr if security
1266 * context is not set yet */
1267 rc = security_inode_notifysecctx(inode, secctx, secctxlen);
1268 inode_unlock(inode);
1273 d_instantiate(dentry, inode);
1275 if (!(ll_i2sbi(inode)->ll_flags & LL_SBI_FILE_SECCTX)) {
1276 rc = ll_inode_init_security(dentry, inode, dir);
1281 ll_set_lock_data(ll_i2sbi(dir)->ll_md_exp, inode, it, &bits);
1282 if (bits & MDS_INODELOCK_LOOKUP)
1283 d_lustre_revalidate(dentry);
1288 void ll_update_times(struct ptlrpc_request *request, struct inode *inode)
1290 struct mdt_body *body = req_capsule_server_get(&request->rq_pill,
1294 if (body->mbo_valid & OBD_MD_FLMTIME &&
1295 body->mbo_mtime > inode->i_mtime.tv_sec) {
1297 "setting fid " DFID " mtime from %lld to %llu\n",
1298 PFID(ll_inode2fid(inode)),
1299 (s64)inode->i_mtime.tv_sec, body->mbo_mtime);
1300 inode->i_mtime.tv_sec = body->mbo_mtime;
1303 if (body->mbo_valid & OBD_MD_FLCTIME &&
1304 body->mbo_ctime > inode->i_ctime.tv_sec)
1305 inode->i_ctime.tv_sec = body->mbo_ctime;
1308 static int ll_new_node(struct inode *dir, struct dentry *dchild,
1309 const char *tgt, umode_t mode, int rdev, __u32 opc)
1311 struct qstr *name = &dchild->d_name;
1312 struct ptlrpc_request *request = NULL;
1313 struct md_op_data *op_data;
1314 struct inode *inode = NULL;
1315 struct ll_sb_info *sbi = ll_i2sbi(dir);
1320 if (unlikely(tgt != NULL))
1321 tgt_len = strlen(tgt) + 1;
1324 op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name,
1325 name->len, 0, opc, NULL);
1326 if (IS_ERR(op_data))
1327 GOTO(err_exit, err = PTR_ERR(op_data));
1329 if (sbi->ll_flags & LL_SBI_FILE_SECCTX) {
1330 err = ll_dentry_init_security(dchild, mode, &dchild->d_name,
1331 &op_data->op_file_secctx_name,
1332 &op_data->op_file_secctx,
1333 &op_data->op_file_secctx_size);
1335 GOTO(err_exit, err);
1338 err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode,
1339 from_kuid(&init_user_ns, current_fsuid()),
1340 from_kgid(&init_user_ns, current_fsgid()),
1341 cfs_curproc_cap_pack(), rdev, &request);
1342 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 58, 0)
1344 * server < 2.12.58 doesn't pack default LMV in intent_getattr reply,
1345 * fetch default LMV here.
1347 if (unlikely(err == -EREMOTE)) {
1348 struct ll_inode_info *lli = ll_i2info(dir);
1349 struct lmv_user_md *lum;
1353 ptlrpc_req_finished(request);
1356 err2 = ll_dir_getstripe(dir, (void **)&lum, &lumsize, &request,
1357 OBD_MD_DEFAULT_MEA);
1358 ll_finish_md_op_data(op_data);
1361 struct lustre_md md = { NULL };
1363 md.body = req_capsule_server_get(&request->rq_pill,
1366 GOTO(err_exit, err = -EPROTO);
1368 OBD_ALLOC_PTR(md.default_lmv);
1369 if (!md.default_lmv)
1370 GOTO(err_exit, err = -ENOMEM);
1372 md.default_lmv->lsm_md_magic = lum->lum_magic;
1373 md.default_lmv->lsm_md_stripe_count =
1374 lum->lum_stripe_count;
1375 md.default_lmv->lsm_md_master_mdt_index =
1376 lum->lum_stripe_offset;
1377 md.default_lmv->lsm_md_hash_type = lum->lum_hash_type;
1379 err = ll_update_inode(dir, &md);
1380 md_free_lustre_md(sbi->ll_md_exp, &md);
1382 GOTO(err_exit, err);
1383 } else if (err2 == -ENODATA && lli->lli_default_lsm_md) {
1385 * If there are no default stripe EA on the MDT, but the
1386 * client has default stripe, then it probably means
1387 * default stripe EA has just been deleted.
1389 down_write(&lli->lli_lsm_sem);
1390 if (lli->lli_default_lsm_md)
1391 OBD_FREE_PTR(lli->lli_default_lsm_md);
1392 lli->lli_default_lsm_md = NULL;
1393 up_write(&lli->lli_lsm_sem);
1395 GOTO(err_exit, err);
1398 ptlrpc_req_finished(request);
1405 GOTO(err_exit, err);
1407 ll_update_times(request, dir);
1409 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_NEWNODE_PAUSE, cfs_fail_val);
1411 err = ll_prep_inode(&inode, request, dchild->d_sb, NULL);
1413 GOTO(err_exit, err);
1415 if (sbi->ll_flags & LL_SBI_FILE_SECCTX) {
1417 /* must be done before d_instantiate, because it calls
1418 * security_d_instantiate, which means a getxattr if security
1419 * context is not set yet */
1420 err = security_inode_notifysecctx(inode,
1421 op_data->op_file_secctx,
1422 op_data->op_file_secctx_size);
1423 inode_unlock(inode);
1425 GOTO(err_exit, err);
1428 d_instantiate(dchild, inode);
1430 if (!(sbi->ll_flags & LL_SBI_FILE_SECCTX)) {
1431 err = ll_inode_init_security(dchild, inode, dir);
1433 GOTO(err_exit, err);
1438 if (request != NULL)
1439 ptlrpc_req_finished(request);
1441 if (!IS_ERR_OR_NULL(op_data))
1442 ll_finish_md_op_data(op_data);
1447 static int ll_mknod(struct inode *dir, struct dentry *dchild, ll_umode_t mode,
1450 struct qstr *name = &dchild->d_name;
1454 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p) mode %o dev %x\n",
1455 name->len, name->name, PFID(ll_inode2fid(dir)), dir,
1458 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1459 mode &= ~current_umask();
1461 switch (mode & S_IFMT) {
1463 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
1469 err = ll_new_node(dir, dchild, NULL, mode, old_encode_dev(rdev),
1480 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD, 1);
1485 #ifdef HAVE_IOP_ATOMIC_OPEN
1487 * Plain create. Intent create is handled in atomic_open.
1489 static int ll_create_nd(struct inode *dir, struct dentry *dentry,
1490 umode_t mode, bool want_excl)
1494 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1496 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), "
1497 "flags=%u, excl=%d\n", dentry->d_name.len,
1498 dentry->d_name.name, PFID(ll_inode2fid(dir)),
1499 dir, mode, want_excl);
1501 /* Using mknod(2) to create a regular file is designed to not recognize
1502 * volatile file name, so we use ll_mknod() here. */
1503 rc = ll_mknod(dir, dentry, mode, 0);
1505 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
1507 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, unhashed %d\n",
1508 dentry->d_name.len, dentry->d_name.name, d_unhashed(dentry));
1512 #else /* !HAVE_IOP_ATOMIC_OPEN */
1513 static int ll_create_nd(struct inode *dir, struct dentry *dentry,
1514 ll_umode_t mode, struct nameidata *nd)
1516 struct ll_dentry_data *lld = ll_d2d(dentry);
1517 struct lookup_intent *it = NULL;
1520 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1526 /* LU-8559: use LUSTRE_OPC_CREATE for non atomic open case
1527 * so that volatile file name is recoginized.
1528 * Mknod(2), however, is designed to not recognize volatile
1529 * file name to avoid inode leak under orphan directory until
1531 return ll_new_node(dir, dentry, NULL, mode, 0,
1537 /* Was there an error? Propagate it! */
1538 if (it->it_status) {
1543 rc = ll_create_it(dir, dentry, it, NULL, 0);
1544 if (nd && (nd->flags & LOOKUP_OPEN) && dentry->d_inode) { /* Open */
1547 nd->intent.open.file->private_data = it;
1548 filp = lookup_instantiate_filp(nd, dentry, NULL);
1554 ll_intent_release(it);
1555 OBD_FREE(it, sizeof(*it));
1558 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
1562 #endif /* HAVE_IOP_ATOMIC_OPEN */
1564 static int ll_symlink(struct inode *dir, struct dentry *dchild,
1565 const char *oldpath)
1567 struct qstr *name = &dchild->d_name;
1571 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), target=%.*s\n",
1572 name->len, name->name, PFID(ll_inode2fid(dir)),
1573 dir, 3000, oldpath);
1575 err = ll_new_node(dir, dchild, oldpath, S_IFLNK | S_IRWXUGO, 0,
1576 LUSTRE_OPC_SYMLINK);
1579 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK, 1);
1584 static int ll_link(struct dentry *old_dentry, struct inode *dir,
1585 struct dentry *new_dentry)
1587 struct inode *src = old_dentry->d_inode;
1588 struct qstr *name = &new_dentry->d_name;
1589 struct ll_sb_info *sbi = ll_i2sbi(dir);
1590 struct ptlrpc_request *request = NULL;
1591 struct md_op_data *op_data;
1595 CDEBUG(D_VFSTRACE, "VFS Op: inode="DFID"(%p), dir="DFID"(%p), "
1596 "target=%.*s\n", PFID(ll_inode2fid(src)), src,
1597 PFID(ll_inode2fid(dir)), dir, name->len, name->name);
1599 op_data = ll_prep_md_op_data(NULL, src, dir, name->name, name->len,
1600 0, LUSTRE_OPC_ANY, NULL);
1601 if (IS_ERR(op_data))
1602 RETURN(PTR_ERR(op_data));
1604 err = md_link(sbi->ll_md_exp, op_data, &request);
1605 ll_finish_md_op_data(op_data);
1609 ll_update_times(request, dir);
1610 ll_stats_ops_tally(sbi, LPROC_LL_LINK, 1);
1613 ptlrpc_req_finished(request);
1617 static int ll_mkdir(struct inode *dir, struct dentry *dchild, ll_umode_t mode)
1619 struct qstr *name = &dchild->d_name;
1623 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1624 name->len, name->name, PFID(ll_inode2fid(dir)), dir);
1626 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1627 mode &= ~current_umask();
1629 mode = (mode & (S_IRWXUGO|S_ISVTX)) | S_IFDIR;
1631 err = ll_new_node(dir, dchild, NULL, mode, 0, LUSTRE_OPC_MKDIR);
1633 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR, 1);
1638 static int ll_rmdir(struct inode *dir, struct dentry *dchild)
1640 struct qstr *name = &dchild->d_name;
1641 struct ptlrpc_request *request = NULL;
1642 struct md_op_data *op_data;
1646 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1647 name->len, name->name, PFID(ll_inode2fid(dir)), dir);
1649 if (unlikely(d_mountpoint(dchild)))
1652 op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len,
1653 S_IFDIR, LUSTRE_OPC_ANY, NULL);
1654 if (IS_ERR(op_data))
1655 RETURN(PTR_ERR(op_data));
1657 if (dchild->d_inode != NULL)
1658 op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
1660 op_data->op_fid2 = op_data->op_fid3;
1661 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1662 ll_finish_md_op_data(op_data);
1664 ll_update_times(request, dir);
1665 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
1668 ptlrpc_req_finished(request);
1675 int ll_rmdir_entry(struct inode *dir, char *name, int namelen)
1677 struct ptlrpc_request *request = NULL;
1678 struct md_op_data *op_data;
1682 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1683 namelen, name, PFID(ll_inode2fid(dir)), dir);
1685 op_data = ll_prep_md_op_data(NULL, dir, NULL, name, strlen(name),
1686 S_IFDIR, LUSTRE_OPC_ANY, NULL);
1687 if (IS_ERR(op_data))
1688 RETURN(PTR_ERR(op_data));
1689 op_data->op_cli_flags |= CLI_RM_ENTRY;
1690 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1691 ll_finish_md_op_data(op_data);
1693 ll_update_times(request, dir);
1694 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
1697 ptlrpc_req_finished(request);
1701 static int ll_unlink(struct inode *dir, struct dentry *dchild)
1703 struct qstr *name = &dchild->d_name;
1704 struct ptlrpc_request *request = NULL;
1705 struct md_op_data *op_data;
1706 struct mdt_body *body;
1709 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1710 name->len, name->name, PFID(ll_inode2fid(dir)), dir);
1713 * XXX: unlink bind mountpoint maybe call to here,
1714 * just check it as vfs_unlink does.
1716 if (unlikely(d_mountpoint(dchild)))
1719 op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len, 0,
1720 LUSTRE_OPC_ANY, NULL);
1721 if (IS_ERR(op_data))
1722 RETURN(PTR_ERR(op_data));
1724 op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
1726 op_data->op_fid2 = op_data->op_fid3;
1727 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1728 ll_finish_md_op_data(op_data);
1733 * The server puts attributes in on the last unlink, use them to update
1734 * the link count so the inode can be freed immediately.
1736 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
1737 if (body->mbo_valid & OBD_MD_FLNLINK)
1738 set_nlink(dchild->d_inode, body->mbo_nlink);
1740 ll_update_times(request, dir);
1741 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1);
1744 ptlrpc_req_finished(request);
1748 static int ll_rename(struct inode *src, struct dentry *src_dchild,
1749 struct inode *tgt, struct dentry *tgt_dchild
1750 #ifdef HAVE_IOPS_RENAME_WITH_FLAGS
1751 , unsigned int flags
1755 struct qstr *src_name = &src_dchild->d_name;
1756 struct qstr *tgt_name = &tgt_dchild->d_name;
1757 struct ptlrpc_request *request = NULL;
1758 struct ll_sb_info *sbi = ll_i2sbi(src);
1759 struct md_op_data *op_data;
1763 #ifdef HAVE_IOPS_RENAME_WITH_FLAGS
1768 CDEBUG(D_VFSTRACE, "VFS Op:oldname=%.*s, src_dir="DFID
1769 "(%p), newname=%.*s, tgt_dir="DFID"(%p)\n",
1770 src_name->len, src_name->name,
1771 PFID(ll_inode2fid(src)), src, tgt_name->len,
1772 tgt_name->name, PFID(ll_inode2fid(tgt)), tgt);
1774 if (unlikely(d_mountpoint(src_dchild) || d_mountpoint(tgt_dchild)))
1777 op_data = ll_prep_md_op_data(NULL, src, tgt, NULL, 0, 0,
1778 LUSTRE_OPC_ANY, NULL);
1779 if (IS_ERR(op_data))
1780 RETURN(PTR_ERR(op_data));
1782 if (src_dchild->d_inode != NULL)
1783 op_data->op_fid3 = *ll_inode2fid(src_dchild->d_inode);
1785 if (tgt_dchild->d_inode != NULL)
1786 op_data->op_fid4 = *ll_inode2fid(tgt_dchild->d_inode);
1788 err = md_rename(sbi->ll_md_exp, op_data,
1789 src_name->name, src_name->len,
1790 tgt_name->name, tgt_name->len, &request);
1791 ll_finish_md_op_data(op_data);
1793 ll_update_times(request, src);
1794 ll_update_times(request, tgt);
1795 ll_stats_ops_tally(sbi, LPROC_LL_RENAME, 1);
1798 ptlrpc_req_finished(request);
1801 d_move(src_dchild, tgt_dchild);
1806 const struct inode_operations ll_dir_inode_operations = {
1808 #ifdef HAVE_IOP_ATOMIC_OPEN
1809 .atomic_open = ll_atomic_open,
1811 .lookup = ll_lookup_nd,
1812 .create = ll_create_nd,
1813 /* We need all these non-raw things for NFSD, to not patch it. */
1814 .unlink = ll_unlink,
1817 .symlink = ll_symlink,
1819 .rename = ll_rename,
1820 .setattr = ll_setattr,
1821 .getattr = ll_getattr,
1822 .permission = ll_inode_permission,
1823 #ifdef HAVE_IOP_XATTR
1824 .setxattr = ll_setxattr,
1825 .getxattr = ll_getxattr,
1826 .removexattr = ll_removexattr,
1828 .listxattr = ll_listxattr,
1829 #ifdef HAVE_IOP_GET_ACL
1830 .get_acl = ll_get_acl,
1832 #ifdef HAVE_IOP_SET_ACL
1833 .set_acl = ll_set_acl,
1837 const struct inode_operations ll_special_inode_operations = {
1838 .setattr = ll_setattr,
1839 .getattr = ll_getattr,
1840 .permission = ll_inode_permission,
1841 #ifdef HAVE_IOP_XATTR
1842 .setxattr = ll_setxattr,
1843 .getxattr = ll_getxattr,
1844 .removexattr = ll_removexattr,
1846 .listxattr = ll_listxattr,
1847 #ifdef HAVE_IOP_GET_ACL
1848 .get_acl = ll_get_acl,
1850 #ifdef HAVE_IOP_SET_ACL
1851 .set_acl = ll_set_acl,