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/
33 #include <linux/sched.h>
35 #include <linux/file.h>
36 #include <linux/quotaops.h>
37 #include <linux/highmem.h>
38 #include <linux/pagemap.h>
39 #include <linux/user_namespace.h>
40 #include <linux/uidgid.h>
42 #define DEBUG_SUBSYSTEM S_LLITE
44 #include <obd_support.h>
45 #include <lustre_fid.h>
46 #include <lustre_dlm.h>
47 #include "llite_internal.h"
49 #ifndef HAVE_USER_NAMESPACE_ARG
50 #define ll_create_nd(ns, dir, de, mode, ex) ll_create_nd(dir, de, mode, ex)
51 #define ll_mkdir(ns, dir, dch, mode) ll_mkdir(dir, dch, mode)
52 #define ll_mknod(ns, dir, dch, mode, rd) ll_mknod(dir, dch, mode, rd)
53 #ifdef HAVE_IOPS_RENAME_WITH_FLAGS
54 #define ll_rename(ns, src, sdc, tgt, tdc, fl) ll_rename(src, sdc, tgt, tdc, fl)
56 #define ll_rename(ns, src, sdc, tgt, tdc) ll_rename(src, sdc, tgt, tdc)
57 #endif /* HAVE_IOPS_RENAME_WITH_FLAGS */
58 #define ll_symlink(nd, dir, dch, old) ll_symlink(dir, dch, old)
61 static int ll_create_it(struct inode *dir, struct dentry *dentry,
62 struct lookup_intent *it,
63 void *secctx, __u32 secctxlen, bool encrypt,
64 void *encctx, __u32 encctxlen, unsigned int open_flags);
66 /* called from iget5_locked->find_inode() under inode_lock spinlock */
67 static int ll_test_inode(struct inode *inode, void *opaque)
69 struct ll_inode_info *lli = ll_i2info(inode);
70 struct lustre_md *md = opaque;
72 if (unlikely(!(md->body->mbo_valid & OBD_MD_FLID))) {
73 CERROR("MDS body missing FID\n");
77 if (!lu_fid_eq(&lli->lli_fid, &md->body->mbo_fid1))
83 static int ll_set_inode(struct inode *inode, void *opaque)
85 struct ll_inode_info *lli = ll_i2info(inode);
86 struct mdt_body *body = ((struct lustre_md *)opaque)->body;
88 if (unlikely(!(body->mbo_valid & OBD_MD_FLID))) {
89 CERROR("MDS body missing FID\n");
93 lli->lli_fid = body->mbo_fid1;
94 if (unlikely(!(body->mbo_valid & OBD_MD_FLTYPE))) {
95 CERROR("Can not initialize inode "DFID" without object type: "
97 PFID(&lli->lli_fid), body->mbo_valid);
101 inode->i_mode = (inode->i_mode & ~S_IFMT) | (body->mbo_mode & S_IFMT);
102 if (unlikely(inode->i_mode == 0)) {
103 CERROR("Invalid inode "DFID" type\n", PFID(&lli->lli_fid));
114 * Get an inode by inode number(@hash), which is already instantiated by
115 * the intent lookup).
117 struct inode *ll_iget(struct super_block *sb, ino_t hash,
118 struct lustre_md *md)
126 inode = iget5_locked(sb, hash, ll_test_inode, ll_set_inode, md);
128 RETURN(ERR_PTR(-ENOMEM));
130 if (inode->i_state & I_NEW) {
131 rc = ll_read_inode2(inode, md);
132 if (rc == 0 && S_ISREG(inode->i_mode) &&
133 ll_i2info(inode)->lli_clob == NULL)
134 rc = cl_file_inode_init(inode, md);
137 /* Let's clear directory lsm here, otherwise
138 * make_bad_inode() will reset the inode mode
139 * to regular, then ll_clear_inode will not
140 * be able to clear lsm_md */
141 if (S_ISDIR(inode->i_mode))
142 ll_dir_clear_lsm_md(inode);
143 make_bad_inode(inode);
144 unlock_new_inode(inode);
148 inode_has_no_xattr(inode);
149 unlock_new_inode(inode);
151 } else if (is_bad_inode(inode)) {
153 inode = ERR_PTR(-ESTALE);
154 } else if (!(inode->i_state & (I_FREEING | I_CLEAR))) {
155 rc = ll_update_inode(inode, md);
156 CDEBUG(D_VFSTRACE, "got inode: "DFID"(%p): rc = %d\n",
157 PFID(&md->body->mbo_fid1), inode, rc);
159 if (S_ISDIR(inode->i_mode))
160 ll_dir_clear_lsm_md(inode);
169 /* mark negative sub file dentries invalid and prune unused dentries */
170 static void ll_prune_negative_children(struct inode *dir)
172 struct dentry *dentry;
173 struct dentry *child;
178 spin_lock(&dir->i_lock);
179 hlist_for_each_entry(dentry, &dir->i_dentry, d_alias) {
180 spin_lock(&dentry->d_lock);
181 list_for_each_entry(child, &dentry->d_subdirs, d_child) {
185 spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED);
186 if (lld_is_init(child))
187 ll_d2d(child)->lld_invalid = 1;
188 if (!ll_d_count(child)) {
191 spin_unlock(&child->d_lock);
192 spin_unlock(&dentry->d_lock);
193 spin_unlock(&dir->i_lock);
195 CDEBUG(D_DENTRY, "prune negative dentry %pd\n",
201 spin_unlock(&child->d_lock);
203 spin_unlock(&dentry->d_lock);
205 spin_unlock(&dir->i_lock);
210 int ll_test_inode_by_fid(struct inode *inode, void *opaque)
212 return lu_fid_eq(&ll_i2info(inode)->lli_fid, opaque);
215 static int ll_dom_lock_cancel(struct inode *inode, struct ldlm_lock *lock)
218 struct ll_inode_info *lli = ll_i2info(inode);
223 env = cl_env_get(&refcheck);
225 RETURN(PTR_ERR(env));
227 CFS_FAIL_TIMEOUT(OBD_FAIL_LDLM_REPLAY_PAUSE, cfs_fail_val);
229 /* reach MDC layer to flush data under the DoM ldlm lock */
230 rc = cl_object_flush(env, lli->lli_clob, lock);
231 if (rc == -ENODATA) {
232 CDEBUG(D_INODE, "inode "DFID" layout has no DoM stripe\n",
233 PFID(ll_inode2fid(inode)));
234 /* most likely result of layout change, do nothing */
238 cl_env_put(env, &refcheck);
242 static void ll_lock_cancel_bits(struct ldlm_lock *lock, __u64 to_cancel)
244 struct inode *inode = ll_inode_from_resource_lock(lock);
245 struct ll_inode_info *lli;
246 __u64 bits = to_cancel;
252 /* That means the inode is evicted most likely and may cause
253 * the skipping of lock cleanups below, so print the message
256 if (lock->l_resource->lr_lvb_inode)
258 "can't take inode for the lock (%sevicted)",
259 lock->l_resource->lr_lvb_inode->i_state &
260 I_FREEING ? "" : "not ");
264 if (!fid_res_name_eq(ll_inode2fid(inode),
265 &lock->l_resource->lr_name)) {
266 LDLM_ERROR(lock, "data mismatch with object "DFID"(%p)",
267 PFID(ll_inode2fid(inode)), inode);
271 if (bits & MDS_INODELOCK_XATTR) {
272 ll_xattr_cache_empty(inode);
273 bits &= ~MDS_INODELOCK_XATTR;
276 /* For OPEN locks we differentiate between lock modes
277 * LCK_CR, LCK_CW, LCK_PR - bug 22891 */
278 if (bits & MDS_INODELOCK_OPEN)
279 ll_have_md_lock(lock->l_conn_export, inode, &bits,
282 if (bits & MDS_INODELOCK_OPEN) {
285 switch (lock->l_req_mode) {
296 LDLM_ERROR(lock, "bad lock mode for OPEN lock");
300 ll_md_real_close(inode, fmode);
302 bits &= ~MDS_INODELOCK_OPEN;
305 if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
306 MDS_INODELOCK_LAYOUT | MDS_INODELOCK_PERM |
308 ll_have_md_lock(lock->l_conn_export, inode, &bits, LCK_MINMODE);
310 if (bits & MDS_INODELOCK_DOM) {
311 rc = ll_dom_lock_cancel(inode, lock);
313 CDEBUG(D_INODE, "cannot flush DoM data "
315 PFID(ll_inode2fid(inode)), rc);
318 if (bits & MDS_INODELOCK_LAYOUT) {
319 struct cl_object_conf conf = {
320 .coc_opc = OBJECT_CONF_INVALIDATE,
324 rc = ll_layout_conf(inode, &conf);
326 CDEBUG(D_INODE, "cannot invalidate layout of "
328 PFID(ll_inode2fid(inode)), rc);
331 lli = ll_i2info(inode);
333 if (bits & MDS_INODELOCK_UPDATE)
334 set_bit(LLIF_UPDATE_ATIME, &lli->lli_flags);
336 if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) {
337 CDEBUG(D_INODE, "invalidating inode "DFID" lli = %p, "
338 "pfid = "DFID"\n", PFID(ll_inode2fid(inode)),
339 lli, PFID(&lli->lli_pfid));
340 truncate_inode_pages(inode->i_mapping, 0);
342 if (unlikely(!fid_is_zero(&lli->lli_pfid))) {
343 struct inode *master_inode = NULL;
346 /* This is slave inode, since all of the child dentry
347 * is connected on the master inode, so we have to
348 * invalidate the negative children on master inode */
349 CDEBUG(D_INODE, "Invalidate s"DFID" m"DFID"\n",
350 PFID(ll_inode2fid(inode)), PFID(&lli->lli_pfid));
352 hash = cl_fid_build_ino(&lli->lli_pfid,
353 ll_need_32bit_api(ll_i2sbi(inode)));
355 /* Do not lookup the inode with ilookup5, otherwise
356 * it will cause dead lock,
357 * 1. Client1 send chmod req to the MDT0, then on MDT0,
358 * it enqueues master and all of its slaves lock,
359 * (mdt_attr_set() -> mdt_lock_slaves()), after gets
360 * master and stripe0 lock, it will send the enqueue
361 * req (for stripe1) to MDT1, then MDT1 finds the lock
362 * has been granted to client2. Then MDT1 sends blocking
364 * 2. At the same time, client2 tries to unlink
365 * the striped dir (rm -rf striped_dir), and during
366 * lookup, it will hold the master inode of the striped
367 * directory, whose inode state is NEW, then tries to
368 * revalidate all of its slaves, (ll_prep_inode()->
369 * ll_iget()->ll_read_inode2()-> ll_update_inode().).
370 * And it will be blocked on the server side because
372 * 3. Then the client get the blocking_ast req, cancel
373 * the lock, but being blocked if using ->ilookup5()),
374 * because master inode state is NEW. */
375 master_inode = ilookup5_nowait(inode->i_sb, hash,
376 ll_test_inode_by_fid,
377 (void *)&lli->lli_pfid);
379 ll_prune_negative_children(master_inode);
383 ll_prune_negative_children(inode);
387 /* at umount s_root becomes NULL */
388 if ((bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM)) &&
389 inode->i_sb->s_root && !is_root_inode(inode))
390 ll_prune_aliases(inode);
392 if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM))
393 forget_all_cached_acls(inode);
399 /* Check if the given lock may be downgraded instead of canceling and
400 * that convert is really needed. */
401 static int ll_md_need_convert(struct ldlm_lock *lock)
403 struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
405 __u64 wanted = lock->l_policy_data.l_inodebits.cancel_bits;
406 __u64 bits = lock->l_policy_data.l_inodebits.bits & ~wanted;
407 enum ldlm_mode mode = LCK_MINMODE;
409 if (!lock->l_conn_export ||
410 !exp_connect_lock_convert(lock->l_conn_export))
413 if (!wanted || !bits || ldlm_is_cancel(lock))
416 /* do not convert locks other than DOM for now */
417 if (!((bits | wanted) & MDS_INODELOCK_DOM))
420 /* We may have already remaining bits in some other lock so
421 * lock convert will leave us just extra lock for the same bit.
422 * Check if client has other lock with the same bits and the same
423 * or lower mode and don't convert if any.
425 switch (lock->l_req_mode) {
439 /* do not convert other modes */
443 /* is lock is too old to be converted? */
444 lock_res_and_lock(lock);
445 if (ktime_after(ktime_get(),
446 ktime_add(lock->l_last_used, ns->ns_dirty_age_limit))) {
447 unlock_res_and_lock(lock);
450 unlock_res_and_lock(lock);
452 inode = ll_inode_from_resource_lock(lock);
453 ll_have_md_lock(lock->l_conn_export, inode, &bits, mode);
458 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *ld,
459 void *data, int flag)
461 struct lustre_handle lockh;
467 case LDLM_CB_BLOCKING:
469 __u64 cancel_flags = LCF_ASYNC;
471 /* if lock convert is not needed then still have to
472 * pass lock via ldlm_cli_convert() to keep all states
473 * correct, set cancel_bits to full lock bits to cause
474 * full cancel to happen.
476 if (!ll_md_need_convert(lock)) {
477 lock_res_and_lock(lock);
478 lock->l_policy_data.l_inodebits.cancel_bits =
479 lock->l_policy_data.l_inodebits.bits;
480 unlock_res_and_lock(lock);
482 rc = ldlm_cli_convert(lock, cancel_flags);
485 /* continue with cancel otherwise */
486 ldlm_lock2handle(lock, &lockh);
487 rc = ldlm_cli_cancel(&lockh, cancel_flags);
489 CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc);
494 case LDLM_CB_CANCELING:
496 __u64 to_cancel = lock->l_policy_data.l_inodebits.bits;
498 /* Nothing to do for non-granted locks */
499 if (!ldlm_is_granted(lock))
502 /* If 'ld' is supplied then bits to be cancelled are passed
503 * implicitly by lock converting and cancel_bits from 'ld'
504 * should be used. Otherwise full cancel is being performed
505 * and lock inodebits are used.
507 * Note: we cannot rely on cancel_bits in lock itself at this
508 * moment because they can be changed by concurrent thread,
509 * so ldlm_cli_inodebits_convert() pass cancel bits implicitly
513 /* partial bits cancel allowed only during convert */
514 LASSERT(ldlm_is_converting(lock));
515 /* mask cancel bits by lock bits so only no any unused
516 * bits are passed to ll_lock_cancel_bits()
518 to_cancel &= ld->l_policy_data.l_inodebits.cancel_bits;
520 ll_lock_cancel_bits(lock, to_cancel);
530 __u32 ll_i2suppgid(struct inode *i)
532 if (in_group_p(i->i_gid))
533 return (__u32)from_kgid(&init_user_ns, i->i_gid);
535 return (__u32) __kgid_val(INVALID_GID);
538 /* Pack the required supplementary groups into the supplied groups array. */
539 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
542 LASSERT(suppgids != NULL);
544 suppgids[0] = ll_i2suppgid(i1);
547 suppgids[1] = ll_i2suppgid(i2);
553 * try to reuse three types of dentry:
554 * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid
555 * by concurrent .revalidate).
556 * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may
557 * be cleared by others calling d_lustre_revalidate).
558 * 3. DISCONNECTED alias.
560 static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
562 struct dentry *alias, *discon_alias, *invalid_alias;
564 if (hlist_empty(&inode->i_dentry))
567 discon_alias = invalid_alias = NULL;
569 spin_lock(&inode->i_lock);
570 hlist_for_each_entry(alias, &inode->i_dentry, d_alias) {
571 LASSERT(alias != dentry);
573 spin_lock(&alias->d_lock);
574 if ((alias->d_flags & DCACHE_DISCONNECTED) &&
575 S_ISDIR(inode->i_mode))
576 /* LASSERT(last_discon == NULL); LU-405, bz 20055 */
577 discon_alias = alias;
578 else if (alias->d_parent == dentry->d_parent &&
579 alias->d_name.hash == dentry->d_name.hash &&
580 alias->d_name.len == dentry->d_name.len &&
581 memcmp(alias->d_name.name, dentry->d_name.name,
582 dentry->d_name.len) == 0)
583 invalid_alias = alias;
584 spin_unlock(&alias->d_lock);
589 alias = invalid_alias ?: discon_alias ?: NULL;
591 spin_lock(&alias->d_lock);
593 spin_unlock(&alias->d_lock);
595 spin_unlock(&inode->i_lock);
601 * Similar to d_splice_alias(), but lustre treats invalid alias
602 * similar to DCACHE_DISCONNECTED, and tries to use it anyway.
604 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de)
609 new = ll_find_alias(inode, de);
611 if (!ll_d_setup(new, true))
612 return ERR_PTR(-ENOMEM);
616 "Reuse dentry %p inode %p refc %d flags %#x\n",
617 new, new->d_inode, ll_d_count(new), new->d_flags);
621 if (!ll_d_setup(de, false))
622 return ERR_PTR(-ENOMEM);
625 /* this needs only to be done for foreign symlink dirs as
626 * DCACHE_SYMLINK_TYPE is already set by d_flags_for_inode()
627 * kernel routine for files with symlink ops (ie, real symlink)
629 if (inode && S_ISDIR(inode->i_mode) &&
630 ll_sbi_has_foreign_symlink(ll_i2sbi(inode)) &&
631 #ifdef HAVE_IOP_GET_LINK
632 inode->i_op->get_link) {
634 inode->i_op->follow_link) {
636 CDEBUG(D_INFO, "%s: inode "DFID": faking foreign dir as a symlink\n",
637 ll_i2sbi(inode)->ll_fsname, PFID(ll_inode2fid(inode)));
638 spin_lock(&de->d_lock);
639 /* like d_flags_for_inode() already does for files */
640 de->d_flags = (de->d_flags & ~DCACHE_ENTRY_TYPE) |
642 spin_unlock(&de->d_lock);
645 CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n",
646 de, de->d_inode, ll_d_count(de), de->d_flags);
650 static int ll_lookup_it_finish(struct ptlrpc_request *request,
651 struct lookup_intent *it,
652 struct inode *parent, struct dentry **de,
653 void *secctx, __u32 secctxlen,
654 void *encctx, __u32 encctxlen,
655 ktime_t kstart, bool encrypt)
657 struct inode *inode = NULL;
660 struct dentry *alias;
663 /* NB 1 request reference will be taken away by ll_intent_lock()
665 CDEBUG(D_DENTRY, "it %p it_disposition %x\n", it,
667 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
668 struct req_capsule *pill = &request->rq_pill;
669 struct mdt_body *body = req_capsule_server_get(pill,
672 rc = ll_prep_inode(&inode, &request->rq_pill, (*de)->d_sb, it);
676 /* If encryption context was returned by MDT, put it in
677 * inode now to save an extra getxattr and avoid deadlock.
679 if (body->mbo_valid & OBD_MD_ENCCTX) {
680 encctx = req_capsule_server_get(pill, &RMF_FILE_ENCCTX);
681 encctxlen = req_capsule_get_size(pill,
687 "server returned encryption ctx for "DFID"\n",
688 PFID(ll_inode2fid(inode)));
689 rc = ll_xattr_cache_insert(inode,
690 xattr_for_enc(inode),
693 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
694 ll_i2sbi(inode)->ll_fsname,
695 PFID(ll_inode2fid(inode)), rc);
697 rc = llcrypt_prepare_readdir(inode);
700 "cannot get enc info for "DFID": rc = %d\n",
701 PFID(ll_inode2fid(inode)), rc);
706 ll_set_lock_data(ll_i2sbi(parent)->ll_md_exp, inode, it, &bits);
707 /* OPEN can return data if lock has DoM+LAYOUT bits set */
708 if (it->it_op & IT_OPEN &&
709 bits & MDS_INODELOCK_DOM && bits & MDS_INODELOCK_LAYOUT)
710 ll_dom_finish_open(inode, request);
712 /* We used to query real size from OSTs here, but actually
713 * this is not needed. For stat() calls size would be updated
714 * from subsequent do_revalidate()->ll_inode_revalidate_it() in
716 * vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
717 * Everybody else who needs correct file size would call
718 * ll_glimpse_size or some equivalent themselves anyway.
722 /* If security context was returned by MDT, put it in
723 * inode now to save an extra getxattr from security hooks,
724 * and avoid deadlock.
726 if (body->mbo_valid & OBD_MD_SECCTX) {
727 secctx = req_capsule_server_get(pill, &RMF_FILE_SECCTX);
728 secctxlen = req_capsule_get_size(pill,
733 CDEBUG(D_SEC, "server returned security context"
735 PFID(ll_inode2fid(inode)));
738 /* resume normally on error */
739 ll_inode_notifysecctx(inode, secctx, secctxlen);
742 /* Only hash *de if it is unhashed (new dentry).
743 * Atoimc_open may passin hashed dentries for open.
745 alias = ll_splice_alias(inode, *de);
747 GOTO(out, rc = PTR_ERR(alias));
751 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
752 /* We have the "lookup" lock, so unhide dentry */
753 if (bits & MDS_INODELOCK_LOOKUP)
754 d_lustre_revalidate(*de);
755 /* open may not fetch LOOKUP lock, update dir depth/dmv anyway
756 * in case it's used uninitialized.
758 if (S_ISDIR(inode->i_mode))
759 ll_update_dir_depth_dmv(parent, *de);
762 rc = llcrypt_prepare_readdir(inode);
766 } else if (!it_disposition(it, DISP_OPEN_CREATE)) {
768 * If file was created on the server, the dentry is revalidated
769 * in ll_create_it if the lock allows for it.
771 /* Check that parent has UPDATE lock. */
772 struct lookup_intent parent_it = {
774 .it_lock_handle = 0 };
775 struct ll_inode_info *lli = ll_i2info(parent);
776 struct lu_fid fid = lli->lli_fid;
778 /* If it is striped directory, get the real stripe parent */
779 if (unlikely(ll_dir_striped(parent))) {
780 down_read(&lli->lli_lsm_sem);
781 rc = md_get_fid_from_lsm(ll_i2mdexp(parent),
784 (*de)->d_name.len, &fid);
785 up_read(&lli->lli_lsm_sem);
790 if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it, &fid,
792 d_lustre_revalidate(*de);
793 ll_intent_release(&parent_it);
797 if (it_disposition(it, DISP_OPEN_CREATE)) {
798 ll_stats_ops_tally(ll_i2sbi(parent), LPROC_LL_MKNOD,
799 ktime_us_delta(ktime_get(), kstart));
805 if (rc != 0 && it->it_op & IT_OPEN) {
806 ll_intent_drop_lock(it);
807 ll_open_cleanup((*de)->d_sb, &request->rq_pill);
813 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
814 struct lookup_intent *it,
815 void **secctx, __u32 *secctxlen,
817 struct pcc_create_attach *pca,
819 void **encctx, __u32 *encctxlen)
821 ktime_t kstart = ktime_get();
822 struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
823 struct dentry *save = dentry, *retval;
824 struct ptlrpc_request *req = NULL;
825 struct md_op_data *op_data = NULL;
826 struct lov_user_md *lum = NULL;
827 struct ll_sb_info *sbi = ll_i2sbi(parent);
830 struct llcrypt_name fname;
834 if (dentry->d_name.len > sbi->ll_namelen)
835 RETURN(ERR_PTR(-ENAMETOOLONG));
837 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p), intent=%s\n",
838 dentry, PFID(ll_inode2fid(parent)), parent, LL_IT2STR(it));
840 if (d_mountpoint(dentry))
841 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
843 if (it == NULL || it->it_op == IT_GETXATTR)
846 if (it->it_op == IT_GETATTR && dentry_may_statahead(parent, dentry)) {
847 rc = ll_revalidate_statahead(parent, &dentry, 0);
849 RETURN(dentry == save ? NULL : dentry);
852 if (it->it_op & IT_OPEN && it->it_flags & FMODE_WRITE &&
853 dentry->d_sb->s_flags & SB_RDONLY)
854 RETURN(ERR_PTR(-EROFS));
856 if (it->it_op & IT_CREAT)
857 opc = LUSTRE_OPC_CREATE;
859 opc = LUSTRE_OPC_LOOKUP;
861 rc = ll_prepare_lookup(parent, dentry, &fname, &fid);
863 RETURN(rc != -ENOENT ? ERR_PTR(rc) : NULL);
865 op_data = ll_prep_md_op_data(NULL, parent, NULL, fname.disk_name.name,
866 fname.disk_name.len, 0, opc, NULL);
867 if (IS_ERR(op_data)) {
868 llcrypt_free_filename(&fname);
869 RETURN(ERR_CAST(op_data));
871 if (!fid_is_zero(&fid)) {
872 op_data->op_fid2 = fid;
873 op_data->op_bias = MDS_FID_OP;
874 if (it->it_op & IT_OPEN)
875 it->it_flags |= MDS_OPEN_BY_FID;
878 /* enforce umask if acl disabled or MDS doesn't support umask */
879 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
880 it->it_create_mode &= ~current_umask();
882 if (it->it_op & IT_CREAT &&
883 test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
884 rc = ll_dentry_init_security(dentry, it->it_create_mode,
886 &op_data->op_file_secctx_name,
887 &op_data->op_file_secctx_name_size,
888 &op_data->op_file_secctx,
889 &op_data->op_file_secctx_size,
890 &op_data->op_file_secctx_slot);
892 GOTO(out, retval = ERR_PTR(rc));
894 *secctx = op_data->op_file_secctx;
895 if (secctxlen != NULL)
896 *secctxlen = op_data->op_file_secctx_size;
897 if (secctxslot != NULL)
898 *secctxslot = op_data->op_file_secctx_slot;
902 if (secctxlen != NULL)
904 if (secctxslot != NULL)
907 if (it->it_op & IT_CREAT && encrypt) {
908 if (unlikely(filename_is_volatile(dentry->d_name.name,
909 dentry->d_name.len, NULL))) {
910 /* get encryption context from reference file */
911 int ctx_size = LLCRYPT_ENC_CTX_SIZE;
912 struct lustre_sb_info *lsi;
913 struct file *ref_file;
914 struct inode *ref_inode;
917 rc = volatile_ref_file(dentry->d_name.name,
921 GOTO(out, retval = ERR_PTR(rc));
923 ref_inode = file_inode(ref_file);
926 GOTO(inherit, rc = -EINVAL);
929 lsi = s2lsi(ref_inode->i_sb);
932 OBD_ALLOC(ctx, ctx_size);
934 GOTO(out, retval = ERR_PTR(-ENOMEM));
936 #ifdef CONFIG_LL_ENCRYPTION
937 rc = lsi->lsi_cop->get_context(ref_inode,
939 #elif defined(HAVE_LUSTRE_CRYPTO)
940 rc = ref_inode->i_sb->s_cop->get_context(ref_inode,
946 OBD_FREE(ctx, ctx_size);
952 OBD_FREE(ctx, ctx_size);
956 op_data->op_file_encctx_size = rc;
957 if (rc == ctx_size) {
958 op_data->op_file_encctx = ctx;
960 OBD_ALLOC(op_data->op_file_encctx,
961 op_data->op_file_encctx_size);
962 if (!op_data->op_file_encctx) {
963 OBD_FREE(ctx, ctx_size);
964 GOTO(out, retval = ERR_PTR(-ENOMEM));
966 memcpy(op_data->op_file_encctx, ctx,
967 op_data->op_file_encctx_size);
968 OBD_FREE(ctx, ctx_size);
972 rc = llcrypt_inherit_context(parent, NULL, op_data,
975 GOTO(out, retval = ERR_PTR(rc));
978 *encctx = op_data->op_file_encctx;
979 if (encctxlen != NULL)
980 *encctxlen = op_data->op_file_encctx_size;
984 if (encctxlen != NULL)
988 /* ask for security context upon intent:
989 * get name of security xattr to request to server
991 if (it->it_op & (IT_LOOKUP | IT_GETATTR | IT_OPEN))
992 op_data->op_file_secctx_name_size =
993 ll_secctx_name_get(sbi, &op_data->op_file_secctx_name);
995 if (pca && pca->pca_dataset) {
998 GOTO(out, retval = ERR_PTR(-ENOMEM));
1000 lum->lmm_magic = LOV_USER_MAGIC_V1;
1001 lum->lmm_pattern = LOV_PATTERN_F_RELEASED | LOV_PATTERN_RAID0;
1002 op_data->op_data = lum;
1003 op_data->op_data_size = sizeof(*lum);
1004 op_data->op_archive_id = pca->pca_dataset->pccd_rwid;
1005 it->it_flags |= MDS_OPEN_PCC;
1008 rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
1009 &ll_md_blocking_ast, 0);
1010 /* If the MDS allows the client to chgrp (CFS_SETGRP_PERM), but the
1011 * client does not know which suppgid should be sent to the MDS, or
1012 * some other(s) changed the target file's GID after this RPC sent
1013 * to the MDS with the suppgid as the original GID, then we should
1014 * try again with right suppgid. */
1015 if (rc == -EACCES && it->it_op & IT_OPEN &&
1016 it_disposition(it, DISP_OPEN_DENY)) {
1017 struct mdt_body *body;
1019 LASSERT(req != NULL);
1021 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1022 if (op_data->op_suppgids[0] == body->mbo_gid ||
1023 op_data->op_suppgids[1] == body->mbo_gid ||
1024 !in_group_p(make_kgid(&init_user_ns, body->mbo_gid)))
1025 GOTO(out, retval = ERR_PTR(-EACCES));
1027 fid_zero(&op_data->op_fid2);
1028 op_data->op_suppgids[1] = body->mbo_gid;
1029 ptlrpc_req_finished(req);
1031 ll_intent_release(it);
1032 rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
1033 &ll_md_blocking_ast, 0);
1037 GOTO(out, retval = ERR_PTR(rc));
1039 if (pca && pca->pca_dataset) {
1040 rc = pcc_inode_create(parent->i_sb, pca->pca_dataset,
1044 GOTO(out, retval = ERR_PTR(rc));
1047 /* dir layout may change */
1048 ll_unlock_md_op_lsm(op_data);
1049 rc = ll_lookup_it_finish(req, it, parent, &dentry,
1050 secctx != NULL ? *secctx : NULL,
1051 secctxlen != NULL ? *secctxlen : 0,
1052 encctx != NULL ? *encctx : NULL,
1053 encctxlen != NULL ? *encctxlen : 0,
1056 ll_intent_release(it);
1057 GOTO(out, retval = ERR_PTR(rc));
1060 if ((it->it_op & IT_OPEN) && dentry->d_inode &&
1061 !S_ISREG(dentry->d_inode->i_mode) &&
1062 !S_ISDIR(dentry->d_inode->i_mode)) {
1063 ll_release_openhandle(dentry, it);
1065 ll_lookup_finish_locks(it, dentry);
1067 GOTO(out, retval = (dentry == save) ? NULL : dentry);
1070 if (op_data != NULL && !IS_ERR(op_data)) {
1071 if (secctx != NULL && secctxlen != NULL) {
1072 /* caller needs sec ctx info, so reset it in op_data to
1073 * prevent it from being freed */
1074 op_data->op_file_secctx = NULL;
1075 op_data->op_file_secctx_size = 0;
1077 if (encctx != NULL && encctxlen != NULL &&
1078 it->it_op & IT_CREAT && encrypt) {
1079 /* caller needs enc ctx info, so reset it in op_data to
1080 * prevent it from being freed
1082 op_data->op_file_encctx = NULL;
1083 op_data->op_file_encctx_size = 0;
1085 llcrypt_free_filename(&fname);
1086 ll_finish_md_op_data(op_data);
1092 ptlrpc_req_finished(req);
1096 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
1099 struct lookup_intent *itp, it = { .it_op = IT_GETATTR };
1100 struct dentry *de = NULL;
1102 /* VFS has locked the inode before calling this */
1103 ll_set_inode_lock_owner(parent);
1105 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p), flags=%u\n",
1106 dentry, PFID(ll_inode2fid(parent)), parent, flags);
1109 * Optimize away (CREATE && !OPEN). Let .create handle the race.
1110 * but only if we have write permissions there, otherwise we need
1111 * to proceed with lookup. LU-4185
1113 if ((flags & LOOKUP_CREATE) && !(flags & LOOKUP_OPEN) &&
1114 (inode_permission(&init_user_ns,
1115 parent, MAY_WRITE | MAY_EXEC) == 0))
1118 if (flags & (LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE))
1122 de = ll_lookup_it(parent, dentry, itp, NULL, NULL, NULL, NULL, false,
1126 ll_intent_release(itp);
1129 ll_clear_inode_lock_owner(parent);
1134 #ifdef FMODE_CREATED /* added in Linux v4.18-rc1-20-g73a09dd */
1135 # define ll_is_opened(o, f) ((f)->f_mode & FMODE_OPENED)
1136 # define ll_finish_open(f, d, o) finish_open((f), (d), NULL)
1137 # define ll_last_arg
1138 # define ll_set_created(o, f) \
1140 (f)->f_mode |= FMODE_CREATED; \
1144 # define ll_is_opened(o, f) (*(o))
1145 # define ll_finish_open(f, d, o) finish_open((f), (d), NULL, (o))
1146 # define ll_last_arg , int *opened
1147 # define ll_set_created(o, f) \
1149 *(o) |= FILE_CREATED; \
1155 * For cached negative dentry and new dentry, handle lookup/create/open
1158 static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
1159 struct file *file, unsigned open_flags,
1160 umode_t mode ll_last_arg)
1162 struct lookup_intent *it;
1164 long long lookup_flags = LOOKUP_OPEN;
1165 void *secctx = NULL;
1166 __u32 secctxlen = 0;
1168 void *encctx = NULL;
1169 __u32 encctxlen = 0;
1170 struct ll_sb_info *sbi = NULL;
1171 struct pcc_create_attach pca = { NULL, NULL };
1172 bool encrypt = false;
1177 /* VFS has locked the inode before calling this */
1178 ll_set_inode_lock_owner(dir);
1181 "VFS Op:name=%pd, dir="DFID"(%p), file %p, open_flags %x, mode %x opened %d\n",
1182 dentry, PFID(ll_inode2fid(dir)), dir, file, open_flags, mode,
1183 ll_is_opened(opened, file));
1185 /* Only negative dentries enter here */
1186 LASSERT(dentry->d_inode == NULL);
1188 if (!d_unhashed(dentry)) {
1189 /* A valid negative dentry that just passed revalidation,
1190 * there's little point to try and open it server-side,
1191 * even though there's a minuscule chance it might succeed.
1192 * Either way it's a valid race to just return -ENOENT here.
1194 if (!(open_flags & O_CREAT))
1195 GOTO(clear, rc = -ENOENT);
1197 /* Otherwise we just unhash it to be rehashed afresh via
1198 * lookup if necessary
1203 OBD_ALLOC(it, sizeof(*it));
1205 GOTO(clear, rc = -ENOMEM);
1207 it->it_op = IT_OPEN;
1208 if (open_flags & O_CREAT) {
1209 it->it_op |= IT_CREAT;
1210 lookup_flags |= LOOKUP_CREATE;
1211 sbi = ll_i2sbi(dir);
1212 /* Volatile file is used for HSM restore, so do not use PCC */
1213 if (!filename_is_volatile(dentry->d_name.name,
1214 dentry->d_name.len, NULL)) {
1215 struct pcc_matcher item;
1216 struct pcc_dataset *dataset;
1218 item.pm_uid = from_kuid(&init_user_ns, current_uid());
1219 item.pm_gid = from_kgid(&init_user_ns, current_gid());
1220 item.pm_projid = ll_i2info(dir)->lli_projid;
1221 item.pm_name = &dentry->d_name;
1222 dataset = pcc_dataset_match_get(&sbi->ll_pcc_super,
1224 pca.pca_dataset = dataset;
1227 it->it_create_mode = (mode & S_IALLUGO) | S_IFREG;
1228 it->it_flags = (open_flags & ~O_ACCMODE) | OPEN_FMODE(open_flags);
1229 it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
1231 if (ll_sbi_has_encrypt(ll_i2sbi(dir)) && IS_ENCRYPTED(dir)) {
1232 /* in case of create, this is going to be a regular file because
1233 * we set S_IFREG bit on it->it_create_mode above
1235 rc = llcrypt_prepare_readdir(dir);
1237 GOTO(out_release, rc);
1239 if (open_flags & O_CREAT) {
1240 /* For migration or mirroring without enc key, we still
1241 * need to be able to create a volatile file.
1243 if (!llcrypt_has_encryption_key(dir) &&
1244 (!filename_is_volatile(dentry->d_name.name,
1245 dentry->d_name.len, NULL) ||
1246 (open_flags & O_FILE_ENC) != O_FILE_ENC ||
1247 !(open_flags & O_DIRECT)))
1248 GOTO(out_release, rc = -ENOKEY);
1252 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE2, cfs_fail_val);
1254 /* We can only arrive at this path when we have no inode, so
1255 * we only need to request open lock if it was requested
1258 if (ll_i2info(dir)->lli_open_thrsh_count != UINT_MAX)
1259 open_threshold = ll_i2info(dir)->lli_open_thrsh_count;
1261 open_threshold = ll_i2sbi(dir)->ll_oc_thrsh_count;
1263 if (open_threshold == 1 &&
1264 exp_connect_flags2(ll_i2mdexp(dir)) &
1265 OBD_CONNECT2_ATOMIC_OPEN_LOCK)
1266 it->it_flags |= MDS_OPEN_LOCK;
1268 /* Dentry added to dcache tree in ll_lookup_it */
1269 de = ll_lookup_it(dir, dentry, it, &secctx, &secctxlen, &secctxslot,
1270 &pca, encrypt, &encctx, &encctxlen);
1273 else if (de != NULL)
1276 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1279 if (it_disposition(it, DISP_OPEN_CREATE)) {
1280 /* Dentry instantiated in ll_create_it. */
1281 rc = ll_create_it(dir, dentry, it, secctx, secctxlen,
1282 encrypt, encctx, encctxlen,
1284 ll_security_release_secctx(secctx, secctxlen,
1286 llcrypt_free_ctx(encctx, encctxlen);
1288 /* We dget in ll_splice_alias. */
1294 rc = pcc_inode_create_fini(dentry->d_inode, &pca);
1298 GOTO(out_release, rc);
1301 ll_set_created(opened, file);
1303 /* Open the file with O_CREAT, but the file already
1304 * existed on MDT. This may happend in the case that
1305 * the LOOKUP ibits lock is revoked and the
1306 * corresponding dentry cache is deleted.
1307 * i.e. In the current Lustre, the truncate operation
1308 * will revoke the LOOKUP ibits lock, and the file
1309 * dentry cache will be invalidated. The following open
1310 * with O_CREAT flag will call into ->atomic_open, the
1311 * file was wrongly though as newly created file and
1312 * try to auto cache the file. So after client knows it
1313 * is not a DISP_OPEN_CREATE, it should cleanup the
1314 * already created PCC copy.
1316 pcc_create_attach_cleanup(dir->i_sb, &pca);
1318 if (open_flags & O_CREAT && encrypt &&
1320 rc = ll_set_encflags(dentry->d_inode, encctx,
1322 llcrypt_free_ctx(encctx, encctxlen);
1324 GOTO(out_release, rc);
1328 /* check also if a foreign file is openable */
1329 if (dentry->d_inode && it_disposition(it, DISP_OPEN_OPEN) &&
1330 ll_foreign_is_openable(dentry, open_flags)) {
1332 if (S_ISFIFO(dentry->d_inode->i_mode)) {
1333 /* We cannot call open here as it might
1334 * deadlock. This case is unreachable in
1335 * practice because of OBD_CONNECT_NODEVOH. */
1336 rc = finish_no_open(file, de);
1338 file->private_data = it;
1339 rc = ll_finish_open(file, dentry, opened);
1340 /* We dget in ll_splice_alias. finish_open takes
1341 * care of dget for fd open.
1347 rc = finish_no_open(file, de);
1350 pcc_create_attach_cleanup(dir->i_sb, &pca);
1354 ll_intent_release(it);
1355 OBD_FREE(it, sizeof(*it));
1357 ll_clear_inode_lock_owner(dir);
1362 /* We depend on "mode" being set with the proper file type/umask by now */
1363 static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
1365 struct inode *inode = NULL;
1366 struct ptlrpc_request *request = NULL;
1367 struct ll_sb_info *sbi = ll_i2sbi(dir);
1371 LASSERT(it && it->it_disposition);
1373 LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
1374 request = it->it_request;
1375 it_clear_disposition(it, DISP_ENQ_CREATE_REF);
1376 rc = ll_prep_inode(&inode, &request->rq_pill, dir->i_sb, it);
1378 GOTO(out, inode = ERR_PTR(rc));
1380 /* Pause to allow for a race with concurrent access by fid */
1381 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_NODE_PAUSE, cfs_fail_val);
1383 /* We asked for a lock on the directory, but were granted a
1384 * lock on the inode. Since we finally have an inode pointer,
1385 * stuff it in the lock. */
1386 CDEBUG(D_DLMTRACE, "setting l_ast_data to inode "DFID"(%p)\n",
1387 PFID(ll_inode2fid(inode)), inode);
1388 ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
1391 ptlrpc_req_finished(request);
1396 * By the time this is called, we already have created the directory cache
1397 * entry for the new file, but it is so far negative - it has no inode.
1399 * We defer creating the OBD object(s) until open, to keep the intent and
1400 * non-intent code paths similar, and also because we do not have the MDS
1401 * inode number before calling ll_create_node() (which is needed for LOV),
1402 * so we would need to do yet another RPC to the MDS to store the LOV EA
1403 * data on the MDS. If needed, we would pass the PACKED lmm as data and
1404 * lmm_size in datalen (the MDS still has code which will handle that).
1406 * If the create succeeds, we fill in the inode information
1407 * with d_instantiate().
1409 static int ll_create_it(struct inode *dir, struct dentry *dentry,
1410 struct lookup_intent *it,
1411 void *secctx, __u32 secctxlen, bool encrypt,
1412 void *encctx, __u32 encctxlen, unsigned int open_flags)
1414 struct inode *inode;
1419 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p), intent=%s\n",
1420 dentry, PFID(ll_inode2fid(dir)), dir, LL_IT2STR(it));
1422 rc = it_open_error(DISP_OPEN_CREATE, it);
1426 inode = ll_create_node(dir, it);
1428 RETURN(PTR_ERR(inode));
1430 /* must be done before d_instantiate, because it calls
1431 * security_d_instantiate, which means a getxattr if security
1432 * context is not set yet
1434 rc = ll_inode_notifysecctx(inode, secctx, secctxlen);
1438 d_instantiate(dentry, inode);
1441 bool preload = true;
1443 /* For migration or mirroring without enc key, we
1444 * create a volatile file without enc context.
1446 if (!llcrypt_has_encryption_key(dir) &&
1447 filename_is_volatile(dentry->d_name.name,
1448 dentry->d_name.len, NULL) &&
1449 (open_flags & O_FILE_ENC) == O_FILE_ENC &&
1450 open_flags & O_DIRECT)
1452 rc = ll_set_encflags(inode, encctx, encctxlen, preload);
1457 if (!test_bit(LL_SBI_FILE_SECCTX, ll_i2sbi(inode)->ll_flags)) {
1458 rc = ll_inode_init_security(dentry, inode, dir);
1463 ll_set_lock_data(ll_i2sbi(dir)->ll_md_exp, inode, it, &bits);
1464 if (bits & MDS_INODELOCK_LOOKUP) {
1465 d_lustre_revalidate(dentry);
1466 if (S_ISDIR(inode->i_mode))
1467 ll_update_dir_depth_dmv(dir, dentry);
1473 void ll_update_times(struct ptlrpc_request *request, struct inode *inode)
1475 struct mdt_body *body = req_capsule_server_get(&request->rq_pill,
1479 if (body->mbo_valid & OBD_MD_FLMTIME &&
1480 body->mbo_mtime > inode->i_mtime.tv_sec) {
1482 "setting fid " DFID " mtime from %lld to %llu\n",
1483 PFID(ll_inode2fid(inode)),
1484 (s64)inode->i_mtime.tv_sec, body->mbo_mtime);
1485 inode->i_mtime.tv_sec = body->mbo_mtime;
1488 if (body->mbo_valid & OBD_MD_FLCTIME &&
1489 body->mbo_ctime > inode->i_ctime.tv_sec)
1490 inode->i_ctime.tv_sec = body->mbo_ctime;
1493 /* once default LMV (space balanced) is set on ROOT, it should take effect if
1494 * default LMV is not set on parent directory.
1496 static void ll_qos_mkdir_prep(struct md_op_data *op_data, struct inode *dir)
1498 struct inode *root = dir->i_sb->s_root->d_inode;
1499 struct ll_inode_info *rlli = ll_i2info(root);
1500 struct ll_inode_info *lli = ll_i2info(dir);
1501 struct lmv_stripe_md *lsm;
1502 unsigned short depth;
1504 op_data->op_dir_depth = lli->lli_inherit_depth ?: lli->lli_dir_depth;
1505 depth = lli->lli_dir_depth;
1507 /* parent directory is striped */
1508 if (unlikely(lli->lli_lsm_md))
1511 /* default LMV set on parent directory */
1512 if (unlikely(lli->lli_default_lsm_md))
1515 /* parent is ROOT */
1516 if (unlikely(dir == root))
1519 /* default LMV not set on ROOT */
1520 if (!rlli->lli_default_lsm_md)
1523 down_read(&rlli->lli_lsm_sem);
1524 lsm = rlli->lli_default_lsm_md;
1528 /* not space balanced */
1529 if (lsm->lsm_md_master_mdt_index != LMV_OFFSET_DEFAULT)
1533 * Check if the fs default is to be applied.
1534 * depth == 0 means 'not inited' for not root dir.
1536 if (lsm->lsm_md_max_inherit != LMV_INHERIT_NONE &&
1537 (lsm->lsm_md_max_inherit == LMV_INHERIT_UNLIMITED ||
1538 (depth && lsm->lsm_md_max_inherit > depth))) {
1539 op_data->op_flags |= MF_QOS_MKDIR;
1540 if (lsm->lsm_md_max_inherit_rr != LMV_INHERIT_RR_NONE &&
1541 (lsm->lsm_md_max_inherit_rr == LMV_INHERIT_RR_UNLIMITED ||
1542 (depth && lsm->lsm_md_max_inherit_rr > depth)))
1543 op_data->op_flags |= MF_RR_MKDIR;
1544 CDEBUG(D_INODE, DFID" requests qos mkdir %#x\n",
1545 PFID(&lli->lli_fid), op_data->op_flags);
1548 up_read(&rlli->lli_lsm_sem);
1551 static int ll_new_node(struct inode *dir, struct dentry *dchild,
1552 const char *tgt, umode_t mode, __u64 rdev, __u32 opc)
1554 struct qstr *name = &dchild->d_name;
1555 struct ptlrpc_request *request = NULL;
1556 struct md_op_data *op_data = NULL;
1557 struct inode *inode = NULL;
1558 struct ll_sb_info *sbi = ll_i2sbi(dir);
1559 struct llcrypt_str *disk_link = NULL;
1560 bool encrypt = false;
1561 struct lmv_user_md *lum = NULL;
1562 const void *data = NULL;
1567 if (unlikely(tgt != NULL)) {
1568 disk_link = (struct llcrypt_str *)rdev;
1572 data = disk_link->name;
1573 datalen = disk_link->len;
1577 op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name,
1578 name->len, 0, opc, NULL);
1579 if (IS_ERR(op_data))
1580 GOTO(err_exit, err = PTR_ERR(op_data));
1582 if (S_ISDIR(mode)) {
1583 ll_qos_mkdir_prep(op_data, dir);
1584 if ((exp_connect_flags2(ll_i2mdexp(dir)) &
1585 OBD_CONNECT2_DMV_IMP_INHERIT) &&
1586 op_data->op_default_mea1 && !lum) {
1587 const struct lmv_stripe_md *lsm;
1589 /* once DMV_IMP_INHERIT is set, pack default LMV in
1594 GOTO(err_exit, err = -ENOMEM);
1596 lsm = op_data->op_default_mea1;
1597 lum->lum_magic = cpu_to_le32(lsm->lsm_md_magic);
1598 lum->lum_stripe_count =
1599 cpu_to_le32(lsm->lsm_md_stripe_count);
1600 lum->lum_stripe_offset =
1601 cpu_to_le32(lsm->lsm_md_master_mdt_index);
1602 lum->lum_hash_type =
1603 cpu_to_le32(lsm->lsm_md_hash_type);
1604 lum->lum_max_inherit = lsm->lsm_md_max_inherit;
1605 lum->lum_max_inherit_rr = lsm->lsm_md_max_inherit_rr;
1606 lum->lum_pool_name[0] = 0;
1607 op_data->op_bias |= MDS_CREATE_DEFAULT_LMV;
1609 datalen = sizeof(*lum);
1613 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
1614 err = ll_dentry_init_security(dchild, mode, &dchild->d_name,
1615 &op_data->op_file_secctx_name,
1616 &op_data->op_file_secctx_name_size,
1617 &op_data->op_file_secctx,
1618 &op_data->op_file_secctx_size,
1619 &op_data->op_file_secctx_slot);
1621 GOTO(err_exit, err);
1624 if (ll_sbi_has_encrypt(sbi) &&
1625 ((IS_ENCRYPTED(dir) &&
1626 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) ||
1627 (unlikely(ll_sb_has_test_dummy_encryption(dir->i_sb)) &&
1629 err = llcrypt_prepare_readdir(dir);
1631 GOTO(err_exit, err);
1632 if (!llcrypt_has_encryption_key(dir))
1633 GOTO(err_exit, err = -ENOKEY);
1638 err = llcrypt_inherit_context(dir, NULL, op_data, false);
1640 GOTO(err_exit, err);
1642 if (S_ISLNK(mode)) {
1643 /* llcrypt needs inode to encrypt target name, so create
1644 * a fake inode and associate encryption context got
1645 * from llcrypt_inherit_context.
1647 struct inode *fakeinode =
1648 dchild->d_sb->s_op->alloc_inode(dchild->d_sb);
1651 GOTO(err_exit, err = -ENOMEM);
1652 fakeinode->i_sb = dchild->d_sb;
1653 fakeinode->i_mode |= S_IFLNK;
1655 fakeinode->i_opflags |= IOP_XATTR;
1657 ll_lli_init(ll_i2info(fakeinode));
1658 err = ll_set_encflags(fakeinode,
1659 op_data->op_file_encctx,
1660 op_data->op_file_encctx_size,
1663 err = __llcrypt_encrypt_symlink(fakeinode, tgt,
1667 ll_xattr_cache_destroy(fakeinode);
1668 llcrypt_put_encryption_info(fakeinode);
1669 dchild->d_sb->s_op->destroy_inode(fakeinode);
1671 GOTO(err_exit, err);
1673 data = disk_link->name;
1674 datalen = disk_link->len;
1678 err = md_create(sbi->ll_md_exp, op_data, data, datalen, mode,
1679 from_kuid(&init_user_ns, current_fsuid()),
1680 from_kgid(&init_user_ns, current_fsgid()),
1681 current_cap(), rdev, &request);
1682 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 17, 58, 0)
1684 * server < 2.12.58 doesn't pack default LMV in intent_getattr reply,
1685 * fetch default LMV here.
1687 if (unlikely(err == -EREMOTE)) {
1688 struct ll_inode_info *lli = ll_i2info(dir);
1689 struct lmv_user_md *lum;
1693 ptlrpc_req_finished(request);
1695 ll_finish_md_op_data(op_data);
1698 err2 = ll_dir_getstripe(dir, (void **)&lum, &lumsize, &request,
1699 OBD_MD_DEFAULT_MEA);
1701 struct lustre_md md = { NULL };
1703 md.body = req_capsule_server_get(&request->rq_pill,
1706 GOTO(err_exit, err = -EPROTO);
1708 OBD_ALLOC_PTR(md.default_lmv);
1709 if (!md.default_lmv)
1710 GOTO(err_exit, err = -ENOMEM);
1712 md.default_lmv->lsm_md_magic = lum->lum_magic;
1713 md.default_lmv->lsm_md_stripe_count =
1714 lum->lum_stripe_count;
1715 md.default_lmv->lsm_md_master_mdt_index =
1716 lum->lum_stripe_offset;
1717 md.default_lmv->lsm_md_hash_type = lum->lum_hash_type;
1718 md.default_lmv->lsm_md_max_inherit =
1719 lum->lum_max_inherit;
1720 md.default_lmv->lsm_md_max_inherit_rr =
1721 lum->lum_max_inherit_rr;
1723 err = ll_update_inode(dir, &md);
1724 md_free_lustre_md(sbi->ll_md_exp, &md);
1726 GOTO(err_exit, err);
1727 } else if (err2 == -ENODATA && lli->lli_default_lsm_md) {
1729 * If there are no default stripe EA on the MDT, but the
1730 * client has default stripe, then it probably means
1731 * default stripe EA has just been deleted.
1733 down_write(&lli->lli_lsm_sem);
1734 if (lli->lli_default_lsm_md)
1735 OBD_FREE_PTR(lli->lli_default_lsm_md);
1736 lli->lli_default_lsm_md = NULL;
1737 up_write(&lli->lli_lsm_sem);
1739 GOTO(err_exit, err);
1742 ptlrpc_req_finished(request);
1749 GOTO(err_exit, err);
1751 ll_update_times(request, dir);
1753 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_NEWNODE_PAUSE, cfs_fail_val);
1755 err = ll_prep_inode(&inode, &request->rq_pill, dchild->d_sb, NULL);
1757 GOTO(err_exit, err);
1759 /* must be done before d_instantiate, because it calls
1760 * security_d_instantiate, which means a getxattr if security
1761 * context is not set yet
1763 err = ll_inode_notifysecctx(inode,
1764 op_data->op_file_secctx,
1765 op_data->op_file_secctx_size);
1767 GOTO(err_exit, err);
1769 d_instantiate(dchild, inode);
1772 err = ll_set_encflags(inode, op_data->op_file_encctx,
1773 op_data->op_file_encctx_size, true);
1775 GOTO(err_exit, err);
1777 if (S_ISLNK(mode)) {
1778 struct ll_inode_info *lli = ll_i2info(inode);
1780 /* Cache the plaintext symlink target
1781 * for later use by get_link()
1783 OBD_ALLOC(lli->lli_symlink_name, strlen(tgt) + 1);
1784 /* do not return an error if we cannot
1785 * cache the symlink locally
1787 if (lli->lli_symlink_name)
1788 memcpy(lli->lli_symlink_name,
1789 tgt, strlen(tgt) + 1);
1793 if (!test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
1794 err = ll_inode_init_security(dchild, inode, dir);
1796 GOTO(err_exit, err);
1801 if (request != NULL)
1802 ptlrpc_req_finished(request);
1803 if (!IS_ERR_OR_NULL(op_data))
1804 ll_finish_md_op_data(op_data);
1811 static int ll_mknod(struct user_namespace *mnt_userns, struct inode *dir,
1812 struct dentry *dchild, umode_t mode, dev_t rdev)
1814 ktime_t kstart = ktime_get();
1818 /* VFS has locked the inode before calling this */
1819 ll_set_inode_lock_owner(dir);
1821 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p) mode %o dev %x\n",
1822 dchild, PFID(ll_inode2fid(dir)), dir, mode, rdev);
1824 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1825 mode &= ~current_umask();
1827 switch (mode & S_IFMT) {
1836 err = ll_new_node(dir, dchild, NULL, mode, old_encode_dev(rdev),
1847 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD,
1848 ktime_us_delta(ktime_get(), kstart));
1849 ll_clear_inode_lock_owner(dir);
1855 * Plain create. Intent create is handled in atomic_open.
1857 static int ll_create_nd(struct user_namespace *mnt_userns,
1858 struct inode *dir, struct dentry *dentry,
1859 umode_t mode, bool want_excl)
1861 ktime_t kstart = ktime_get();
1864 /* VFS has locked the inode before calling this */
1865 ll_set_inode_lock_owner(dir);
1867 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1870 "VFS Op:name=%pd, dir="DFID"(%p), flags=%u, excl=%d\n",
1871 dentry, PFID(ll_inode2fid(dir)), dir, mode, want_excl);
1873 /* Using mknod(2) to create a regular file is designed to not recognize
1874 * volatile file name, so we use ll_mknod() here. */
1875 rc = ll_mknod(mnt_userns, dir, dentry, mode, 0);
1877 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, unhashed %d\n",
1878 dentry, d_unhashed(dentry));
1881 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE,
1882 ktime_us_delta(ktime_get(), kstart));
1884 ll_clear_inode_lock_owner(dir);
1889 static int ll_symlink(struct user_namespace *mnt_userns, struct inode *dir,
1890 struct dentry *dchild, const char *oldpath)
1892 ktime_t kstart = ktime_get();
1893 int len = strlen(oldpath);
1894 struct llcrypt_str disk_link;
1898 /* VFS has locked the inode before calling this */
1899 ll_set_inode_lock_owner(dir);
1901 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p), target=%.*s\n",
1902 dchild, PFID(ll_inode2fid(dir)), dir, 3000, oldpath);
1904 err = llcrypt_prepare_symlink(dir, oldpath, len, dir->i_sb->s_blocksize,
1909 err = ll_new_node(dir, dchild, oldpath, S_IFLNK | S_IRWXUGO,
1910 (__u64)&disk_link, LUSTRE_OPC_SYMLINK);
1912 if (disk_link.name != (unsigned char *)oldpath)
1913 kfree(disk_link.name);
1916 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK,
1917 ktime_us_delta(ktime_get(), kstart));
1920 ll_clear_inode_lock_owner(dir);
1925 static int ll_link(struct dentry *old_dentry, struct inode *dir,
1926 struct dentry *new_dentry)
1928 struct inode *src = old_dentry->d_inode;
1929 struct qstr *name = &new_dentry->d_name;
1930 struct ll_sb_info *sbi = ll_i2sbi(dir);
1931 struct ptlrpc_request *request = NULL;
1932 struct md_op_data *op_data;
1933 ktime_t kstart = ktime_get();
1937 /* VFS has locked the inodes before calling this */
1938 ll_set_inode_lock_owner(src);
1939 ll_set_inode_lock_owner(dir);
1942 "VFS Op: inode="DFID"(%p), dir="DFID"(%p), target=%pd\n",
1943 PFID(ll_inode2fid(src)), src,
1944 PFID(ll_inode2fid(dir)), dir, new_dentry);
1946 err = llcrypt_prepare_link(old_dentry, dir, new_dentry);
1950 op_data = ll_prep_md_op_data(NULL, src, dir, name->name, name->len,
1951 0, LUSTRE_OPC_ANY, NULL);
1952 if (IS_ERR(op_data))
1953 GOTO(clear, err = PTR_ERR(op_data));
1955 err = md_link(sbi->ll_md_exp, op_data, &request);
1956 ll_finish_md_op_data(op_data);
1960 ll_update_times(request, dir);
1961 ll_stats_ops_tally(sbi, LPROC_LL_LINK,
1962 ktime_us_delta(ktime_get(), kstart));
1965 ptlrpc_req_finished(request);
1967 ll_clear_inode_lock_owner(src);
1968 ll_clear_inode_lock_owner(dir);
1973 static int ll_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
1974 struct dentry *dchild, umode_t mode)
1976 ktime_t kstart = ktime_get();
1980 /* VFS has locked the inode before calling this */
1981 ll_set_inode_lock_owner(dir);
1983 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p)\n",
1984 dchild, PFID(ll_inode2fid(dir)), dir);
1986 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1987 mode &= ~current_umask();
1989 mode = (mode & (S_IRWXUGO|S_ISVTX)) | S_IFDIR;
1991 err = ll_new_node(dir, dchild, NULL, mode, 0, LUSTRE_OPC_MKDIR);
1993 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR,
1994 ktime_us_delta(ktime_get(), kstart));
1996 ll_clear_inode_lock_owner(dir);
2001 static int ll_rmdir(struct inode *dir, struct dentry *dchild)
2003 struct qstr *name = &dchild->d_name;
2004 struct ptlrpc_request *request = NULL;
2005 struct md_op_data *op_data;
2006 ktime_t kstart = ktime_get();
2011 /* VFS has locked the inodes before calling this */
2012 ll_set_inode_lock_owner(dir);
2013 ll_set_inode_lock_owner(dchild->d_inode);
2015 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p)\n",
2016 dchild, PFID(ll_inode2fid(dir)), dir);
2018 if (unlikely(d_mountpoint(dchild)))
2019 GOTO(out, rc = -EBUSY);
2021 /* some foreign dir may not be allowed to be removed */
2022 if (!ll_foreign_is_removable(dchild, false))
2023 GOTO(out, rc = -EPERM);
2025 op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len,
2026 S_IFDIR, LUSTRE_OPC_ANY, NULL);
2027 if (IS_ERR(op_data))
2028 GOTO(out, rc = PTR_ERR(op_data));
2030 if (dchild->d_inode != NULL)
2031 op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
2033 if (fid_is_zero(&op_data->op_fid2))
2034 op_data->op_fid2 = op_data->op_fid3;
2035 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
2036 ll_finish_md_op_data(op_data);
2038 struct mdt_body *body;
2040 ll_update_times(request, dir);
2041 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR,
2042 ktime_us_delta(ktime_get(), kstart));
2045 * The server puts attributes in on the last unlink, use them
2046 * to update the link count so the inode can be freed
2049 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
2050 if (body->mbo_valid & OBD_MD_FLNLINK) {
2051 spin_lock(&dchild->d_inode->i_lock);
2052 set_nlink(dchild->d_inode, body->mbo_nlink);
2053 spin_unlock(&dchild->d_inode->i_lock);
2057 ptlrpc_req_finished(request);
2059 ll_clear_inode_lock_owner(dir);
2060 ll_clear_inode_lock_owner(dchild->d_inode);
2068 int ll_rmdir_entry(struct inode *dir, char *name, int namelen)
2070 struct ptlrpc_request *request = NULL;
2071 struct md_op_data *op_data;
2072 ktime_t kstart = ktime_get();
2076 CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
2077 namelen, name, PFID(ll_inode2fid(dir)), dir);
2079 op_data = ll_prep_md_op_data(NULL, dir, NULL, name, strlen(name),
2080 S_IFDIR, LUSTRE_OPC_ANY, NULL);
2081 if (IS_ERR(op_data))
2082 RETURN(PTR_ERR(op_data));
2083 op_data->op_cli_flags |= CLI_RM_ENTRY;
2084 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
2085 ll_finish_md_op_data(op_data);
2087 ll_update_times(request, dir);
2089 ptlrpc_req_finished(request);
2091 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR,
2092 ktime_us_delta(ktime_get(), kstart));
2096 static int ll_unlink(struct inode *dir, struct dentry *dchild)
2098 struct qstr *name = &dchild->d_name;
2099 struct ptlrpc_request *request = NULL;
2100 struct md_op_data *op_data;
2101 struct mdt_body *body;
2102 ktime_t kstart = ktime_get();
2107 /* VFS has locked the inodes before calling this */
2108 ll_set_inode_lock_owner(dir);
2109 ll_set_inode_lock_owner(dchild->d_inode);
2111 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p)\n",
2112 dchild, PFID(ll_inode2fid(dir)), dir);
2115 * XXX: unlink bind mountpoint maybe call to here,
2116 * just check it as vfs_unlink does.
2118 if (unlikely(d_mountpoint(dchild)))
2119 GOTO(clear, rc = -EBUSY);
2121 /* some foreign file/dir may not be allowed to be unlinked */
2122 if (!ll_foreign_is_removable(dchild, false))
2123 GOTO(clear, rc = -EPERM);
2125 op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len, 0,
2126 LUSTRE_OPC_ANY, NULL);
2127 if (IS_ERR(op_data))
2128 GOTO(clear, rc = PTR_ERR(op_data));
2130 op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
2131 /* notify lower layer if inode has dirty pages */
2132 if (S_ISREG(dchild->d_inode->i_mode) &&
2133 ll_i2info(dchild->d_inode)->lli_clob &&
2134 dirty_cnt(dchild->d_inode))
2135 op_data->op_cli_flags |= CLI_DIRTY_DATA;
2136 if (fid_is_zero(&op_data->op_fid2))
2137 op_data->op_fid2 = op_data->op_fid3;
2138 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
2139 ll_finish_md_op_data(op_data);
2144 * The server puts attributes in on the last unlink, use them to update
2145 * the link count so the inode can be freed immediately.
2147 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
2148 if (body->mbo_valid & OBD_MD_FLNLINK) {
2149 spin_lock(&dchild->d_inode->i_lock);
2150 set_nlink(dchild->d_inode, body->mbo_nlink);
2151 spin_unlock(&dchild->d_inode->i_lock);
2154 ll_update_times(request, dir);
2157 ptlrpc_req_finished(request);
2159 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK,
2160 ktime_us_delta(ktime_get(), kstart));
2162 ll_clear_inode_lock_owner(dir);
2163 ll_clear_inode_lock_owner(dchild->d_inode);
2167 static int ll_rename(struct user_namespace *mnt_userns,
2168 struct inode *src, struct dentry *src_dchild,
2169 struct inode *tgt, struct dentry *tgt_dchild
2170 #if defined(HAVE_USER_NAMESPACE_ARG) || defined(HAVE_IOPS_RENAME_WITH_FLAGS)
2171 , unsigned int flags
2175 struct ptlrpc_request *request = NULL;
2176 struct ll_sb_info *sbi = ll_i2sbi(src);
2177 struct md_op_data *op_data;
2178 ktime_t kstart = ktime_get();
2180 struct llcrypt_name foldname, fnewname;
2184 /* VFS has locked the inodes before calling this */
2185 ll_set_inode_lock_owner(src);
2186 ll_set_inode_lock_owner(tgt);
2187 if (tgt_dchild->d_inode)
2188 ll_set_inode_lock_owner(tgt_dchild->d_inode);
2190 #if defined(HAVE_USER_NAMESPACE_ARG) || defined(HAVE_IOPS_RENAME_WITH_FLAGS)
2192 GOTO(out, err = -EINVAL);
2196 "VFS Op:oldname=%pd, src_dir="DFID"(%p), newname=%pd, tgt_dir="DFID"(%p)\n",
2197 src_dchild, PFID(ll_inode2fid(src)), src,
2198 tgt_dchild, PFID(ll_inode2fid(tgt)), tgt);
2200 if (unlikely(d_mountpoint(src_dchild) || d_mountpoint(tgt_dchild)))
2201 GOTO(out, err = -EBUSY);
2203 #if defined(HAVE_USER_NAMESPACE_ARG) || defined(HAVE_IOPS_RENAME_WITH_FLAGS)
2204 err = llcrypt_prepare_rename(src, src_dchild, tgt, tgt_dchild, flags);
2206 err = llcrypt_prepare_rename(src, src_dchild, tgt, tgt_dchild, 0);
2210 /* we prevent an encrypted file from being renamed
2211 * into an unencrypted dir
2213 if (IS_ENCRYPTED(src) && !IS_ENCRYPTED(tgt))
2214 GOTO(out, err = -EXDEV);
2216 if (src_dchild->d_inode)
2217 mode = src_dchild->d_inode->i_mode;
2219 if (tgt_dchild->d_inode)
2220 mode = tgt_dchild->d_inode->i_mode;
2222 op_data = ll_prep_md_op_data(NULL, src, tgt, NULL, 0, mode,
2223 LUSTRE_OPC_ANY, NULL);
2224 if (IS_ERR(op_data))
2225 GOTO(out, err = PTR_ERR(op_data));
2227 /* If the client is using a subdir mount and does a rename to what it
2228 * sees as /.fscrypt, interpret it as the .fscrypt dir at fs root.
2230 if (unlikely(is_root_inode(tgt) && !fid_is_root(ll_inode2fid(tgt)) &&
2231 tgt_dchild->d_name.len == strlen(dot_fscrypt_name) &&
2232 strncmp(tgt_dchild->d_name.name, dot_fscrypt_name,
2233 tgt_dchild->d_name.len) == 0))
2234 lu_root_fid(&op_data->op_fid2);
2236 if (src_dchild->d_inode)
2237 op_data->op_fid3 = *ll_inode2fid(src_dchild->d_inode);
2239 if (tgt_dchild->d_inode)
2240 op_data->op_fid4 = *ll_inode2fid(tgt_dchild->d_inode);
2242 err = ll_setup_filename(src, &src_dchild->d_name, 1, &foldname, NULL);
2245 err = ll_setup_filename(tgt, &tgt_dchild->d_name, 1, &fnewname, NULL);
2247 llcrypt_free_filename(&foldname);
2250 err = md_rename(sbi->ll_md_exp, op_data,
2251 foldname.disk_name.name, foldname.disk_name.len,
2252 fnewname.disk_name.name, fnewname.disk_name.len,
2254 llcrypt_free_filename(&foldname);
2255 llcrypt_free_filename(&fnewname);
2256 ll_finish_md_op_data(op_data);
2258 ll_update_times(request, src);
2259 ll_update_times(request, tgt);
2262 ptlrpc_req_finished(request);
2265 d_move(src_dchild, tgt_dchild);
2266 ll_stats_ops_tally(sbi, LPROC_LL_RENAME,
2267 ktime_us_delta(ktime_get(), kstart));
2270 ll_clear_inode_lock_owner(src);
2271 ll_clear_inode_lock_owner(tgt);
2272 if (tgt_dchild->d_inode)
2273 ll_clear_inode_lock_owner(tgt_dchild->d_inode);
2277 const struct inode_operations ll_dir_inode_operations = {
2279 .atomic_open = ll_atomic_open,
2280 .lookup = ll_lookup_nd,
2281 .create = ll_create_nd,
2282 /* We need all these non-raw things for NFSD, to not patch it. */
2283 .unlink = ll_unlink,
2286 .symlink = ll_symlink,
2288 .rename = ll_rename,
2289 .setattr = ll_setattr,
2290 .getattr = ll_getattr,
2291 .permission = ll_inode_permission,
2292 #ifdef HAVE_IOP_XATTR
2293 .setxattr = ll_setxattr,
2294 .getxattr = ll_getxattr,
2295 .removexattr = ll_removexattr,
2297 .listxattr = ll_listxattr,
2298 .get_acl = ll_get_acl,
2299 #ifdef HAVE_IOP_SET_ACL
2300 .set_acl = ll_set_acl,
2304 const struct inode_operations ll_special_inode_operations = {
2305 .setattr = ll_setattr,
2306 .getattr = ll_getattr,
2307 .permission = ll_inode_permission,
2308 #ifdef HAVE_IOP_XATTR
2309 .setxattr = ll_setxattr,
2310 .getxattr = ll_getxattr,
2311 .removexattr = ll_removexattr,
2313 .listxattr = ll_listxattr,
2314 .get_acl = ll_get_acl,
2315 #ifdef HAVE_IOP_SET_ACL
2316 .set_acl = ll_set_acl,