4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 #include <linux/sched.h>
40 #include <linux/quotaops.h>
41 #include <linux/highmem.h>
42 #include <linux/pagemap.h>
43 #include <linux/security.h>
45 #define DEBUG_SUBSYSTEM S_LLITE
47 #include "../include/obd_support.h"
48 #include "../include/lustre_fid.h"
49 #include "../include/lustre_lite.h"
50 #include "../include/lustre_dlm.h"
51 #include "../include/lustre_ver.h"
52 #include "llite_internal.h"
54 static int ll_create_it(struct inode
*, struct dentry
*,
55 int, struct lookup_intent
*);
57 /* called from iget5_locked->find_inode() under inode_hash_lock spinlock */
58 static int ll_test_inode(struct inode
*inode
, void *opaque
)
60 struct ll_inode_info
*lli
= ll_i2info(inode
);
61 struct lustre_md
*md
= opaque
;
63 if (unlikely(!(md
->body
->valid
& OBD_MD_FLID
))) {
64 CERROR("MDS body missing FID\n");
68 if (!lu_fid_eq(&lli
->lli_fid
, &md
->body
->fid1
))
74 static int ll_set_inode(struct inode
*inode
, void *opaque
)
76 struct ll_inode_info
*lli
= ll_i2info(inode
);
77 struct mdt_body
*body
= ((struct lustre_md
*)opaque
)->body
;
79 if (unlikely(!(body
->valid
& OBD_MD_FLID
))) {
80 CERROR("MDS body missing FID\n");
84 lli
->lli_fid
= body
->fid1
;
85 if (unlikely(!(body
->valid
& OBD_MD_FLTYPE
))) {
86 CERROR("Can not initialize inode " DFID
87 " without object type: valid = %#llx\n",
88 PFID(&lli
->lli_fid
), body
->valid
);
92 inode
->i_mode
= (inode
->i_mode
& ~S_IFMT
) | (body
->mode
& S_IFMT
);
93 if (unlikely(inode
->i_mode
== 0)) {
94 CERROR("Invalid inode "DFID
" type\n", PFID(&lli
->lli_fid
));
105 * Get an inode by inode number (already instantiated by the intent lookup).
106 * Returns inode or NULL
108 struct inode
*ll_iget(struct super_block
*sb
, ino_t hash
,
109 struct lustre_md
*md
)
114 inode
= iget5_locked(sb
, hash
, ll_test_inode
, ll_set_inode
, md
);
117 if (inode
->i_state
& I_NEW
) {
120 ll_read_inode2(inode
, md
);
121 if (S_ISREG(inode
->i_mode
) &&
122 ll_i2info(inode
)->lli_clob
== NULL
) {
124 "%s: apply lsm %p to inode "DFID
".\n",
125 ll_get_fsname(sb
, NULL
, 0), md
->lsm
,
126 PFID(ll_inode2fid(inode
)));
127 rc
= cl_file_inode_init(inode
, md
);
130 make_bad_inode(inode
);
131 unlock_new_inode(inode
);
135 unlock_new_inode(inode
);
136 } else if (!(inode
->i_state
& (I_FREEING
| I_CLEAR
)))
137 ll_update_inode(inode
, md
);
138 CDEBUG(D_VFSTRACE
, "got inode: %p for "DFID
"\n",
139 inode
, PFID(&md
->body
->fid1
));
144 static void ll_invalidate_negative_children(struct inode
*dir
)
146 struct dentry
*dentry
, *tmp_subdir
;
147 struct ll_d_hlist_node
*p
;
150 ll_d_hlist_for_each_entry(dentry
, p
, &dir
->i_dentry
, d_u
.d_alias
) {
151 spin_lock(&dentry
->d_lock
);
152 if (!list_empty(&dentry
->d_subdirs
)) {
153 struct dentry
*child
;
155 list_for_each_entry_safe(child
, tmp_subdir
,
158 if (child
->d_inode
== NULL
)
159 d_lustre_invalidate(child
, 1);
162 spin_unlock(&dentry
->d_lock
);
164 ll_unlock_dcache(dir
);
167 int ll_md_blocking_ast(struct ldlm_lock
*lock
, struct ldlm_lock_desc
*desc
,
168 void *data
, int flag
)
170 struct lustre_handle lockh
;
174 case LDLM_CB_BLOCKING
:
175 ldlm_lock2handle(lock
, &lockh
);
176 rc
= ldlm_cli_cancel(&lockh
, LCF_ASYNC
);
178 CDEBUG(D_INODE
, "ldlm_cli_cancel: rc = %d\n", rc
);
182 case LDLM_CB_CANCELING
: {
183 struct inode
*inode
= ll_inode_from_resource_lock(lock
);
184 __u64 bits
= lock
->l_policy_data
.l_inodebits
.bits
;
186 /* Inode is set to lock->l_resource->lr_lvb_inode
187 * for mdc - bug 24555 */
188 LASSERT(lock
->l_ast_data
== NULL
);
193 /* Invalidate all dentries associated with this inode */
194 LASSERT(lock
->l_flags
& LDLM_FL_CANCELING
);
196 if (!fid_res_name_eq(ll_inode2fid(inode
),
197 &lock
->l_resource
->lr_name
)) {
198 LDLM_ERROR(lock
, "data mismatch with object "DFID
"(%p)",
199 PFID(ll_inode2fid(inode
)), inode
);
203 if (bits
& MDS_INODELOCK_XATTR
) {
204 ll_xattr_cache_destroy(inode
);
205 bits
&= ~MDS_INODELOCK_XATTR
;
208 /* For OPEN locks we differentiate between lock modes
209 * LCK_CR, LCK_CW, LCK_PR - bug 22891 */
210 if (bits
& MDS_INODELOCK_OPEN
)
211 ll_have_md_lock(inode
, &bits
, lock
->l_req_mode
);
213 if (bits
& MDS_INODELOCK_OPEN
) {
216 switch (lock
->l_req_mode
) {
227 LDLM_ERROR(lock
, "bad lock mode for OPEN lock");
231 ll_md_real_close(inode
, fmode
);
234 if (bits
& (MDS_INODELOCK_LOOKUP
| MDS_INODELOCK_UPDATE
|
235 MDS_INODELOCK_LAYOUT
| MDS_INODELOCK_PERM
))
236 ll_have_md_lock(inode
, &bits
, LCK_MINMODE
);
238 if (bits
& MDS_INODELOCK_LAYOUT
) {
239 struct cl_object_conf conf
= {
240 .coc_opc
= OBJECT_CONF_INVALIDATE
,
244 rc
= ll_layout_conf(inode
, &conf
);
246 CDEBUG(D_INODE
, "cannot invalidate layout of "
248 PFID(ll_inode2fid(inode
)), rc
);
251 if (bits
& MDS_INODELOCK_UPDATE
) {
252 struct ll_inode_info
*lli
= ll_i2info(inode
);
254 spin_lock(&lli
->lli_lock
);
255 lli
->lli_flags
&= ~LLIF_MDS_SIZE_LOCK
;
256 spin_unlock(&lli
->lli_lock
);
259 if ((bits
& MDS_INODELOCK_UPDATE
) && S_ISDIR(inode
->i_mode
)) {
260 CDEBUG(D_INODE
, "invalidating inode %lu\n",
262 truncate_inode_pages(inode
->i_mapping
, 0);
263 ll_invalidate_negative_children(inode
);
266 if ((bits
& (MDS_INODELOCK_LOOKUP
| MDS_INODELOCK_PERM
)) &&
267 inode
->i_sb
->s_root
!= NULL
&&
268 !is_root_inode(inode
))
269 ll_invalidate_aliases(inode
);
281 __u32
ll_i2suppgid(struct inode
*i
)
283 if (in_group_p(i
->i_gid
))
284 return (__u32
)from_kgid(&init_user_ns
, i
->i_gid
);
289 /* Pack the required supplementary groups into the supplied groups array.
290 * If we don't need to use the groups from the target inode(s) then we
291 * instead pack one or more groups from the user's supplementary group
292 * array in case it might be useful. Not needed if doing an MDS-side upcall. */
293 void ll_i2gids(__u32
*suppgids
, struct inode
*i1
, struct inode
*i2
)
300 LASSERT(suppgids
!= NULL
);
302 suppgids
[0] = ll_i2suppgid(i1
);
305 suppgids
[1] = ll_i2suppgid(i2
);
310 for (i
= 0; i
< current_ngroups
; i
++) {
311 if (suppgids
[0] == -1) {
312 if (current_groups
[i
] != suppgids
[1])
313 suppgids
[0] = current_groups
[i
];
316 if (suppgids
[1] == -1) {
317 if (current_groups
[i
] != suppgids
[0])
318 suppgids
[1] = current_groups
[i
];
327 * try to reuse three types of dentry:
328 * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid
329 * by concurrent .revalidate).
330 * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may
331 * be cleared by others calling d_lustre_revalidate).
332 * 3. DISCONNECTED alias.
334 static struct dentry
*ll_find_alias(struct inode
*inode
, struct dentry
*dentry
)
336 struct dentry
*alias
, *discon_alias
, *invalid_alias
;
337 struct ll_d_hlist_node
*p
;
339 if (ll_d_hlist_empty(&inode
->i_dentry
))
342 discon_alias
= invalid_alias
= NULL
;
344 ll_lock_dcache(inode
);
345 ll_d_hlist_for_each_entry(alias
, p
, &inode
->i_dentry
, d_u
.d_alias
) {
346 LASSERT(alias
!= dentry
);
348 spin_lock(&alias
->d_lock
);
349 if (alias
->d_flags
& DCACHE_DISCONNECTED
)
350 /* LASSERT(last_discon == NULL); LU-405, bz 20055 */
351 discon_alias
= alias
;
352 else if (alias
->d_parent
== dentry
->d_parent
&&
353 alias
->d_name
.hash
== dentry
->d_name
.hash
&&
354 alias
->d_name
.len
== dentry
->d_name
.len
&&
355 memcmp(alias
->d_name
.name
, dentry
->d_name
.name
,
356 dentry
->d_name
.len
) == 0)
357 invalid_alias
= alias
;
358 spin_unlock(&alias
->d_lock
);
363 alias
= invalid_alias
?: discon_alias
?: NULL
;
365 spin_lock(&alias
->d_lock
);
367 spin_unlock(&alias
->d_lock
);
369 ll_unlock_dcache(inode
);
375 * Similar to d_splice_alias(), but lustre treats invalid alias
376 * similar to DCACHE_DISCONNECTED, and tries to use it anyway.
378 struct dentry
*ll_splice_alias(struct inode
*inode
, struct dentry
*de
)
384 new = ll_find_alias(inode
, de
);
394 "Reuse dentry %p inode %p refc %d flags %#x\n",
395 new, new->d_inode
, d_count(new), new->d_flags
);
403 CDEBUG(D_DENTRY
, "Add dentry %p inode %p refc %d flags %#x\n",
404 de
, de
->d_inode
, d_count(de
), de
->d_flags
);
408 static int ll_lookup_it_finish(struct ptlrpc_request
*request
,
409 struct lookup_intent
*it
,
410 struct inode
*parent
, struct dentry
**de
)
412 struct inode
*inode
= NULL
;
416 /* NB 1 request reference will be taken away by ll_intent_lock()
418 CDEBUG(D_DENTRY
, "it %p it_disposition %x\n", it
,
419 it
->d
.lustre
.it_disposition
);
420 if (!it_disposition(it
, DISP_LOOKUP_NEG
)) {
421 rc
= ll_prep_inode(&inode
, request
, (*de
)->d_sb
, it
);
425 ll_set_lock_data(ll_i2sbi(parent
)->ll_md_exp
, inode
, it
, &bits
);
427 /* We used to query real size from OSTs here, but actually
428 this is not needed. For stat() calls size would be updated
429 from subsequent do_revalidate()->ll_inode_revalidate_it() in
431 vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
432 Everybody else who needs correct file size would call
433 ll_glimpse_size or some equivalent themselves anyway.
434 Also see bug 7198. */
437 /* Only hash *de if it is unhashed (new dentry).
438 * Atoimc_open may passing hashed dentries for open.
440 if (d_unhashed(*de
)) {
441 struct dentry
*alias
;
443 alias
= ll_splice_alias(inode
, *de
);
445 return PTR_ERR(alias
);
447 } else if (!it_disposition(it
, DISP_LOOKUP_NEG
) &&
448 !it_disposition(it
, DISP_OPEN_CREATE
)) {
449 /* With DISP_OPEN_CREATE dentry will
450 instantiated in ll_create_it. */
451 LASSERT((*de
)->d_inode
== NULL
);
452 d_instantiate(*de
, inode
);
455 if (!it_disposition(it
, DISP_LOOKUP_NEG
)) {
456 /* we have lookup look - unhide dentry */
457 if (bits
& MDS_INODELOCK_LOOKUP
)
458 d_lustre_revalidate(*de
);
459 } else if (!it_disposition(it
, DISP_OPEN_CREATE
)) {
460 /* If file created on server, don't depend on parent UPDATE
461 * lock to unhide it. It is left hidden and next lookup can
462 * find it in ll_splice_alias.
464 /* Check that parent has UPDATE lock. */
465 struct lookup_intent parent_it
= {
467 .d
.lustre
.it_lock_handle
= 0 };
469 if (md_revalidate_lock(ll_i2mdexp(parent
), &parent_it
,
470 &ll_i2info(parent
)->lli_fid
, NULL
)) {
471 d_lustre_revalidate(*de
);
472 ll_intent_release(&parent_it
);
479 static struct dentry
*ll_lookup_it(struct inode
*parent
, struct dentry
*dentry
,
480 struct lookup_intent
*it
, int lookup_flags
)
482 struct lookup_intent lookup_it
= { .it_op
= IT_LOOKUP
};
483 struct dentry
*save
= dentry
, *retval
;
484 struct ptlrpc_request
*req
= NULL
;
486 struct md_op_data
*op_data
;
490 if (dentry
->d_name
.len
> ll_i2sbi(parent
)->ll_namelen
)
491 return ERR_PTR(-ENAMETOOLONG
);
493 CDEBUG(D_VFSTRACE
, "VFS Op:name=%pd,dir=%lu/%u(%p),intent=%s\n",
494 dentry
, parent
->i_ino
,
495 parent
->i_generation
, parent
, LL_IT2STR(it
));
497 if (d_mountpoint(dentry
))
498 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it
));
500 if (it
== NULL
|| it
->it_op
== IT_GETXATTR
)
503 if (it
->it_op
== IT_GETATTR
) {
504 rc
= ll_statahead_enter(parent
, &dentry
, 0);
514 if (it
->it_op
& IT_CREAT
)
515 opc
= LUSTRE_OPC_CREATE
;
517 opc
= LUSTRE_OPC_ANY
;
519 op_data
= ll_prep_md_op_data(NULL
, parent
, NULL
, dentry
->d_name
.name
,
520 dentry
->d_name
.len
, lookup_flags
, opc
,
523 return (void *)op_data
;
525 /* enforce umask if acl disabled or MDS doesn't support umask */
526 if (!IS_POSIXACL(parent
) || !exp_connect_umask(ll_i2mdexp(parent
)))
527 it
->it_create_mode
&= ~current_umask();
529 rc
= md_intent_lock(ll_i2mdexp(parent
), op_data
, NULL
, 0, it
,
530 lookup_flags
, &req
, ll_md_blocking_ast
, 0);
531 ll_finish_md_op_data(op_data
);
533 retval
= ERR_PTR(rc
);
537 rc
= ll_lookup_it_finish(req
, it
, parent
, &dentry
);
539 ll_intent_release(it
);
540 retval
= ERR_PTR(rc
);
544 inode
= dentry
->d_inode
;
545 if ((it
->it_op
& IT_OPEN
) && inode
&&
546 !S_ISREG(inode
->i_mode
) &&
547 !S_ISDIR(inode
->i_mode
)) {
548 ll_release_openhandle(inode
, it
);
550 ll_lookup_finish_locks(it
, inode
);
559 ptlrpc_req_finished(req
);
560 if (it
->it_op
== IT_GETATTR
&& (retval
== NULL
|| retval
== dentry
))
561 ll_statahead_mark(parent
, dentry
);
565 static struct dentry
*ll_lookup_nd(struct inode
*parent
, struct dentry
*dentry
,
568 struct lookup_intent
*itp
, it
= { .it_op
= IT_GETATTR
};
571 CDEBUG(D_VFSTRACE
, "VFS Op:name=%pd,dir=%lu/%u(%p),flags=%u\n",
572 dentry
, parent
->i_ino
,
573 parent
->i_generation
, parent
, flags
);
575 /* Optimize away (CREATE && !OPEN). Let .create handle the race. */
576 if ((flags
& LOOKUP_CREATE
) && !(flags
& LOOKUP_OPEN
))
579 if (flags
& (LOOKUP_PARENT
|LOOKUP_OPEN
|LOOKUP_CREATE
))
583 de
= ll_lookup_it(parent
, dentry
, itp
, 0);
586 ll_intent_release(itp
);
592 * For cached negative dentry and new dentry, handle lookup/create/open
595 static int ll_atomic_open(struct inode
*dir
, struct dentry
*dentry
,
596 struct file
*file
, unsigned open_flags
,
597 umode_t mode
, int *opened
)
599 struct lookup_intent
*it
;
601 long long lookup_flags
= LOOKUP_OPEN
;
605 "VFS Op:name=%pd,dir=%lu/%u(%p),file %p,open_flags %x,mode %x opened %d\n",
607 dir
->i_generation
, dir
, file
, open_flags
, mode
, *opened
);
609 it
= kzalloc(sizeof(*it
), GFP_NOFS
);
614 if (open_flags
& O_CREAT
) {
615 it
->it_op
|= IT_CREAT
;
616 lookup_flags
|= LOOKUP_CREATE
;
618 it
->it_create_mode
= (mode
& S_IALLUGO
) | S_IFREG
;
619 it
->it_flags
= (open_flags
& ~O_ACCMODE
) | OPEN_FMODE(open_flags
);
621 /* Dentry added to dcache tree in ll_lookup_it */
622 de
= ll_lookup_it(dir
, dentry
, it
, lookup_flags
);
629 if (it_disposition(it
, DISP_OPEN_CREATE
)) {
630 /* Dentry instantiated in ll_create_it. */
631 rc
= ll_create_it(dir
, dentry
, mode
, it
);
633 /* We dget in ll_splice_alias. */
639 *opened
|= FILE_CREATED
;
641 if (dentry
->d_inode
&& it_disposition(it
, DISP_OPEN_OPEN
)) {
643 if (S_ISFIFO(dentry
->d_inode
->i_mode
)) {
644 /* We cannot call open here as it would
647 if (it_disposition(it
, DISP_ENQ_OPEN_REF
))
649 (struct ptlrpc_request
*)
650 it
->d
.lustre
.it_data
);
651 rc
= finish_no_open(file
, de
);
653 file
->private_data
= it
;
654 rc
= finish_open(file
, dentry
, NULL
, opened
);
655 /* We dget in ll_splice_alias. finish_open takes
656 * care of dget for fd open.
662 rc
= finish_no_open(file
, de
);
667 ll_intent_release(it
);
668 OBD_FREE(it
, sizeof(*it
));
674 /* We depend on "mode" being set with the proper file type/umask by now */
675 static struct inode
*ll_create_node(struct inode
*dir
, struct lookup_intent
*it
)
677 struct inode
*inode
= NULL
;
678 struct ptlrpc_request
*request
= NULL
;
679 struct ll_sb_info
*sbi
= ll_i2sbi(dir
);
682 LASSERT(it
&& it
->d
.lustre
.it_disposition
);
684 LASSERT(it_disposition(it
, DISP_ENQ_CREATE_REF
));
685 request
= it
->d
.lustre
.it_data
;
686 it_clear_disposition(it
, DISP_ENQ_CREATE_REF
);
687 rc
= ll_prep_inode(&inode
, request
, dir
->i_sb
, it
);
693 LASSERT(ll_d_hlist_empty(&inode
->i_dentry
));
695 /* We asked for a lock on the directory, but were granted a
696 * lock on the inode. Since we finally have an inode pointer,
697 * stuff it in the lock. */
698 CDEBUG(D_DLMTRACE
, "setting l_ast_data to inode %p (%lu/%u)\n",
699 inode
, inode
->i_ino
, inode
->i_generation
);
700 ll_set_lock_data(sbi
->ll_md_exp
, inode
, it
, NULL
);
702 ptlrpc_req_finished(request
);
707 * By the time this is called, we already have created the directory cache
708 * entry for the new file, but it is so far negative - it has no inode.
710 * We defer creating the OBD object(s) until open, to keep the intent and
711 * non-intent code paths similar, and also because we do not have the MDS
712 * inode number before calling ll_create_node() (which is needed for LOV),
713 * so we would need to do yet another RPC to the MDS to store the LOV EA
714 * data on the MDS. If needed, we would pass the PACKED lmm as data and
715 * lmm_size in datalen (the MDS still has code which will handle that).
717 * If the create succeeds, we fill in the inode information
718 * with d_instantiate().
720 static int ll_create_it(struct inode
*dir
, struct dentry
*dentry
, int mode
,
721 struct lookup_intent
*it
)
726 CDEBUG(D_VFSTRACE
, "VFS Op:name=%pd,dir=%lu/%u(%p),intent=%s\n",
728 dir
->i_generation
, dir
, LL_IT2STR(it
));
730 rc
= it_open_error(DISP_OPEN_CREATE
, it
);
734 inode
= ll_create_node(dir
, it
);
736 return PTR_ERR(inode
);
738 d_instantiate(dentry
, inode
);
742 static void ll_update_times(struct ptlrpc_request
*request
,
745 struct mdt_body
*body
= req_capsule_server_get(&request
->rq_pill
,
749 if (body
->valid
& OBD_MD_FLMTIME
&&
750 body
->mtime
> LTIME_S(inode
->i_mtime
)) {
751 CDEBUG(D_INODE
, "setting ino %lu mtime from %lu to %llu\n",
752 inode
->i_ino
, LTIME_S(inode
->i_mtime
), body
->mtime
);
753 LTIME_S(inode
->i_mtime
) = body
->mtime
;
755 if (body
->valid
& OBD_MD_FLCTIME
&&
756 body
->ctime
> LTIME_S(inode
->i_ctime
))
757 LTIME_S(inode
->i_ctime
) = body
->ctime
;
760 static int ll_new_node(struct inode
*dir
, struct dentry
*dentry
,
761 const char *tgt
, int mode
, int rdev
,
764 struct ptlrpc_request
*request
= NULL
;
765 struct md_op_data
*op_data
;
766 struct inode
*inode
= NULL
;
767 struct ll_sb_info
*sbi
= ll_i2sbi(dir
);
771 if (unlikely(tgt
!= NULL
))
772 tgt_len
= strlen(tgt
) + 1;
774 op_data
= ll_prep_md_op_data(NULL
, dir
, NULL
,
778 if (IS_ERR(op_data
)) {
779 err
= PTR_ERR(op_data
);
783 err
= md_create(sbi
->ll_md_exp
, op_data
, tgt
, tgt_len
, mode
,
784 from_kuid(&init_user_ns
, current_fsuid()),
785 from_kgid(&init_user_ns
, current_fsgid()),
786 cfs_curproc_cap_pack(), rdev
, &request
);
787 ll_finish_md_op_data(op_data
);
791 ll_update_times(request
, dir
);
793 err
= ll_prep_inode(&inode
, request
, dir
->i_sb
, NULL
);
797 d_instantiate(dentry
, inode
);
799 ptlrpc_req_finished(request
);
804 static int ll_mknod(struct inode
*dir
, struct dentry
*dchild
,
805 umode_t mode
, dev_t rdev
)
809 CDEBUG(D_VFSTRACE
, "VFS Op:name=%pd,dir=%lu/%u(%p) mode %o dev %x\n",
810 dchild
, dir
->i_ino
, dir
->i_generation
, dir
,
811 mode
, old_encode_dev(rdev
));
813 if (!IS_POSIXACL(dir
) || !exp_connect_umask(ll_i2mdexp(dir
)))
814 mode
&= ~current_umask();
816 switch (mode
& S_IFMT
) {
818 mode
|= S_IFREG
; /* for mode = 0 case, fallthrough */
824 err
= ll_new_node(dir
, dchild
, NULL
, mode
,
825 old_encode_dev(rdev
),
836 ll_stats_ops_tally(ll_i2sbi(dir
), LPROC_LL_MKNOD
, 1);
842 * Plain create. Intent create is handled in atomic_open.
844 static int ll_create_nd(struct inode
*dir
, struct dentry
*dentry
,
845 umode_t mode
, bool want_excl
)
849 CDEBUG(D_VFSTRACE
, "VFS Op:name=%pd,dir=%lu/%u(%p),flags=%u, excl=%d\n",
851 dir
->i_generation
, dir
, mode
, want_excl
);
853 rc
= ll_mknod(dir
, dentry
, mode
, 0);
855 ll_stats_ops_tally(ll_i2sbi(dir
), LPROC_LL_CREATE
, 1);
857 CDEBUG(D_VFSTRACE
, "VFS Op:name=%pd, unhashed %d\n",
858 dentry
, d_unhashed(dentry
));
863 static inline void ll_get_child_fid(struct dentry
*child
, struct lu_fid
*fid
)
866 *fid
= *ll_inode2fid(child
->d_inode
);
872 int ll_rmdir_entry(struct inode
*dir
, char *name
, int namelen
)
874 struct ptlrpc_request
*request
= NULL
;
875 struct md_op_data
*op_data
;
878 CDEBUG(D_VFSTRACE
, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
879 namelen
, name
, dir
->i_ino
, dir
->i_generation
, dir
);
881 op_data
= ll_prep_md_op_data(NULL
, dir
, NULL
, name
, strlen(name
),
882 S_IFDIR
, LUSTRE_OPC_ANY
, NULL
);
884 return PTR_ERR(op_data
);
885 op_data
->op_cli_flags
|= CLI_RM_ENTRY
;
886 rc
= md_unlink(ll_i2sbi(dir
)->ll_md_exp
, op_data
, &request
);
887 ll_finish_md_op_data(op_data
);
889 ll_update_times(request
, dir
);
890 ll_stats_ops_tally(ll_i2sbi(dir
), LPROC_LL_RMDIR
, 1);
893 ptlrpc_req_finished(request
);
897 int ll_objects_destroy(struct ptlrpc_request
*request
, struct inode
*dir
)
899 struct mdt_body
*body
;
900 struct lov_mds_md
*eadata
;
901 struct lov_stripe_md
*lsm
= NULL
;
902 struct obd_trans_info oti
= { 0 };
904 struct obd_capa
*oc
= NULL
;
907 /* req is swabbed so this is safe */
908 body
= req_capsule_server_get(&request
->rq_pill
, &RMF_MDT_BODY
);
909 if (!(body
->valid
& OBD_MD_FLEASIZE
))
912 if (body
->eadatasize
== 0) {
913 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
918 /* The MDS sent back the EA because we unlinked the last reference
919 * to this file. Use this EA to unlink the objects on the OST.
920 * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
921 * check it is complete and sensible. */
922 eadata
= req_capsule_server_sized_get(&request
->rq_pill
, &RMF_MDT_MD
,
924 LASSERT(eadata
!= NULL
);
926 rc
= obd_unpackmd(ll_i2dtexp(dir
), &lsm
, eadata
, body
->eadatasize
);
928 CERROR("obd_unpackmd: %d\n", rc
);
931 LASSERT(rc
>= sizeof(*lsm
));
939 oa
->o_oi
= lsm
->lsm_oi
;
940 oa
->o_mode
= body
->mode
& S_IFMT
;
941 oa
->o_valid
= OBD_MD_FLID
| OBD_MD_FLTYPE
| OBD_MD_FLGROUP
;
943 if (body
->valid
& OBD_MD_FLCOOKIE
) {
944 oa
->o_valid
|= OBD_MD_FLCOOKIE
;
946 req_capsule_server_sized_get(&request
->rq_pill
,
948 sizeof(struct llog_cookie
) *
949 lsm
->lsm_stripe_count
);
950 if (oti
.oti_logcookies
== NULL
) {
951 oa
->o_valid
&= ~OBD_MD_FLCOOKIE
;
952 body
->valid
&= ~OBD_MD_FLCOOKIE
;
956 if (body
->valid
& OBD_MD_FLOSSCAPA
) {
957 rc
= md_unpack_capa(ll_i2mdexp(dir
), request
, &RMF_CAPA2
, &oc
);
962 rc
= obd_destroy(NULL
, ll_i2dtexp(dir
), oa
, lsm
, &oti
,
963 ll_i2mdexp(dir
), oc
);
966 CERROR("obd destroy objid "DOSTID
" error %d\n",
967 POSTID(&lsm
->lsm_oi
), rc
);
969 obd_free_memmd(ll_i2dtexp(dir
), &lsm
);
975 /* ll_unlink() doesn't update the inode with the new link count.
976 * Instead, ll_ddelete() and ll_d_iput() will update it based upon if there
977 * is any lock existing. They will recycle dentries and inodes based upon locks
979 static int ll_unlink(struct inode
*dir
, struct dentry
*dentry
)
981 struct ptlrpc_request
*request
= NULL
;
982 struct md_op_data
*op_data
;
985 CDEBUG(D_VFSTRACE
, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
986 dentry
, dir
->i_ino
, dir
->i_generation
, dir
);
988 op_data
= ll_prep_md_op_data(NULL
, dir
, NULL
,
991 0, LUSTRE_OPC_ANY
, NULL
);
993 return PTR_ERR(op_data
);
995 ll_get_child_fid(dentry
, &op_data
->op_fid3
);
996 op_data
->op_fid2
= op_data
->op_fid3
;
997 rc
= md_unlink(ll_i2sbi(dir
)->ll_md_exp
, op_data
, &request
);
998 ll_finish_md_op_data(op_data
);
1002 ll_update_times(request
, dir
);
1003 ll_stats_ops_tally(ll_i2sbi(dir
), LPROC_LL_UNLINK
, 1);
1005 rc
= ll_objects_destroy(request
, dir
);
1007 ptlrpc_req_finished(request
);
1011 static int ll_mkdir(struct inode
*dir
, struct dentry
*dentry
, ll_umode_t mode
)
1015 CDEBUG(D_VFSTRACE
, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
1016 dentry
, dir
->i_ino
, dir
->i_generation
, dir
);
1018 if (!IS_POSIXACL(dir
) || !exp_connect_umask(ll_i2mdexp(dir
)))
1019 mode
&= ~current_umask();
1020 mode
= (mode
& (S_IRWXUGO
|S_ISVTX
)) | S_IFDIR
;
1021 err
= ll_new_node(dir
, dentry
, NULL
, mode
, 0, LUSTRE_OPC_MKDIR
);
1024 ll_stats_ops_tally(ll_i2sbi(dir
), LPROC_LL_MKDIR
, 1);
1029 static int ll_rmdir(struct inode
*dir
, struct dentry
*dentry
)
1031 struct ptlrpc_request
*request
= NULL
;
1032 struct md_op_data
*op_data
;
1035 CDEBUG(D_VFSTRACE
, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
1036 dentry
, dir
->i_ino
, dir
->i_generation
, dir
);
1038 op_data
= ll_prep_md_op_data(NULL
, dir
, NULL
,
1039 dentry
->d_name
.name
,
1041 S_IFDIR
, LUSTRE_OPC_ANY
, NULL
);
1042 if (IS_ERR(op_data
))
1043 return PTR_ERR(op_data
);
1045 ll_get_child_fid(dentry
, &op_data
->op_fid3
);
1046 op_data
->op_fid2
= op_data
->op_fid3
;
1047 rc
= md_unlink(ll_i2sbi(dir
)->ll_md_exp
, op_data
, &request
);
1048 ll_finish_md_op_data(op_data
);
1050 ll_update_times(request
, dir
);
1051 ll_stats_ops_tally(ll_i2sbi(dir
), LPROC_LL_RMDIR
, 1);
1054 ptlrpc_req_finished(request
);
1058 static int ll_symlink(struct inode
*dir
, struct dentry
*dentry
,
1059 const char *oldname
)
1063 CDEBUG(D_VFSTRACE
, "VFS Op:name=%pd,dir=%lu/%u(%p),target=%.*s\n",
1064 dentry
, dir
->i_ino
, dir
->i_generation
,
1065 dir
, 3000, oldname
);
1067 err
= ll_new_node(dir
, dentry
, oldname
, S_IFLNK
| S_IRWXUGO
,
1068 0, LUSTRE_OPC_SYMLINK
);
1071 ll_stats_ops_tally(ll_i2sbi(dir
), LPROC_LL_SYMLINK
, 1);
1076 static int ll_link(struct dentry
*old_dentry
, struct inode
*dir
,
1077 struct dentry
*new_dentry
)
1079 struct inode
*src
= old_dentry
->d_inode
;
1080 struct ll_sb_info
*sbi
= ll_i2sbi(dir
);
1081 struct ptlrpc_request
*request
= NULL
;
1082 struct md_op_data
*op_data
;
1086 "VFS Op: inode=%lu/%u(%p), dir=%lu/%u(%p), target=%pd\n",
1087 src
->i_ino
, src
->i_generation
, src
, dir
->i_ino
,
1088 dir
->i_generation
, dir
, new_dentry
);
1090 op_data
= ll_prep_md_op_data(NULL
, src
, dir
, new_dentry
->d_name
.name
,
1091 new_dentry
->d_name
.len
,
1092 0, LUSTRE_OPC_ANY
, NULL
);
1093 if (IS_ERR(op_data
))
1094 return PTR_ERR(op_data
);
1096 err
= md_link(sbi
->ll_md_exp
, op_data
, &request
);
1097 ll_finish_md_op_data(op_data
);
1101 ll_update_times(request
, dir
);
1102 ll_stats_ops_tally(sbi
, LPROC_LL_LINK
, 1);
1104 ptlrpc_req_finished(request
);
1108 static int ll_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1109 struct inode
*new_dir
, struct dentry
*new_dentry
)
1111 struct ptlrpc_request
*request
= NULL
;
1112 struct ll_sb_info
*sbi
= ll_i2sbi(old_dir
);
1113 struct md_op_data
*op_data
;
1117 "VFS Op:oldname=%pd,src_dir=%lu/%u(%p),newname=%pd,tgt_dir=%lu/%u(%p)\n",
1118 old_dentry
, old_dir
->i_ino
, old_dir
->i_generation
, old_dir
,
1119 new_dentry
, new_dir
->i_ino
, new_dir
->i_generation
, new_dir
);
1121 op_data
= ll_prep_md_op_data(NULL
, old_dir
, new_dir
, NULL
, 0, 0,
1122 LUSTRE_OPC_ANY
, NULL
);
1123 if (IS_ERR(op_data
))
1124 return PTR_ERR(op_data
);
1126 ll_get_child_fid(old_dentry
, &op_data
->op_fid3
);
1127 ll_get_child_fid(new_dentry
, &op_data
->op_fid4
);
1128 err
= md_rename(sbi
->ll_md_exp
, op_data
,
1129 old_dentry
->d_name
.name
,
1130 old_dentry
->d_name
.len
,
1131 new_dentry
->d_name
.name
,
1132 new_dentry
->d_name
.len
, &request
);
1133 ll_finish_md_op_data(op_data
);
1135 ll_update_times(request
, old_dir
);
1136 ll_update_times(request
, new_dir
);
1137 ll_stats_ops_tally(sbi
, LPROC_LL_RENAME
, 1);
1138 err
= ll_objects_destroy(request
, old_dir
);
1141 ptlrpc_req_finished(request
);
1143 d_move(old_dentry
, new_dentry
);
1147 const struct inode_operations ll_dir_inode_operations
= {
1149 .atomic_open
= ll_atomic_open
,
1150 .lookup
= ll_lookup_nd
,
1151 .create
= ll_create_nd
,
1152 /* We need all these non-raw things for NFSD, to not patch it. */
1153 .unlink
= ll_unlink
,
1156 .symlink
= ll_symlink
,
1158 .rename
= ll_rename
,
1159 .setattr
= ll_setattr
,
1160 .getattr
= ll_getattr
,
1161 .permission
= ll_inode_permission
,
1162 .setxattr
= ll_setxattr
,
1163 .getxattr
= ll_getxattr
,
1164 .listxattr
= ll_listxattr
,
1165 .removexattr
= ll_removexattr
,
1166 .get_acl
= ll_get_acl
,
1169 const struct inode_operations ll_special_inode_operations
= {
1170 .setattr
= ll_setattr
,
1171 .getattr
= ll_getattr
,
1172 .permission
= ll_inode_permission
,
1173 .setxattr
= ll_setxattr
,
1174 .getxattr
= ll_getxattr
,
1175 .listxattr
= ll_listxattr
,
1176 .removexattr
= ll_removexattr
,
1177 .get_acl
= ll_get_acl
,