4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 #include <linux/sched.h>
40 #include <linux/quotaops.h>
41 #include <linux/highmem.h>
42 #include <linux/pagemap.h>
43 #include <linux/security.h>
45 #define DEBUG_SUBSYSTEM S_LLITE
47 #include "../include/obd_support.h"
48 #include "../include/lustre_fid.h"
49 #include "../include/lustre_lite.h"
50 #include "../include/lustre_dlm.h"
51 #include "../include/lustre_ver.h"
52 #include "llite_internal.h"
54 static int ll_create_it(struct inode *, struct dentry *,
55 int, struct lookup_intent *);
57 /* called from iget5_locked->find_inode() under inode_hash_lock spinlock */
58 static int ll_test_inode(struct inode *inode, void *opaque)
60 struct ll_inode_info *lli = ll_i2info(inode);
61 struct lustre_md *md = opaque;
63 if (unlikely(!(md->body->valid & OBD_MD_FLID))) {
64 CERROR("MDS body missing FID\n");
68 if (!lu_fid_eq(&lli->lli_fid, &md->body->fid1))
74 static int ll_set_inode(struct inode *inode, void *opaque)
76 struct ll_inode_info *lli = ll_i2info(inode);
77 struct mdt_body *body = ((struct lustre_md *)opaque)->body;
79 if (unlikely(!(body->valid & OBD_MD_FLID))) {
80 CERROR("MDS body missing FID\n");
84 lli->lli_fid = body->fid1;
85 if (unlikely(!(body->valid & OBD_MD_FLTYPE))) {
86 CERROR("Can not initialize inode " DFID
87 " without object type: valid = %#llx\n",
88 PFID(&lli->lli_fid), body->valid);
92 inode->i_mode = (inode->i_mode & ~S_IFMT) | (body->mode & S_IFMT);
93 if (unlikely(inode->i_mode == 0)) {
94 CERROR("Invalid inode "DFID" type\n", PFID(&lli->lli_fid));
104 * Get an inode by inode number (already instantiated by the intent lookup).
105 * Returns inode or NULL
107 struct inode *ll_iget(struct super_block *sb, ino_t hash,
108 struct lustre_md *md)
113 inode = iget5_locked(sb, hash, ll_test_inode, ll_set_inode, md);
116 if (inode->i_state & I_NEW) {
119 ll_read_inode2(inode, md);
120 if (S_ISREG(inode->i_mode) &&
121 !ll_i2info(inode)->lli_clob) {
123 "%s: apply lsm %p to inode " DFID ".\n",
124 ll_get_fsname(sb, NULL, 0), md->lsm,
125 PFID(ll_inode2fid(inode)));
126 rc = cl_file_inode_init(inode, md);
132 unlock_new_inode(inode);
134 } else if (!(inode->i_state & (I_FREEING | I_CLEAR))) {
135 ll_update_inode(inode, md);
136 CDEBUG(D_VFSTRACE, "got inode: "DFID"(%p)\n",
137 PFID(&md->body->fid1), inode);
143 static void ll_invalidate_negative_children(struct inode *dir)
145 struct dentry *dentry, *tmp_subdir;
148 hlist_for_each_entry(dentry, &dir->i_dentry, d_u.d_alias) {
149 spin_lock(&dentry->d_lock);
150 if (!list_empty(&dentry->d_subdirs)) {
151 struct dentry *child;
153 list_for_each_entry_safe(child, tmp_subdir,
156 if (d_really_is_negative(child))
157 d_lustre_invalidate(child, 1);
160 spin_unlock(&dentry->d_lock);
162 ll_unlock_dcache(dir);
165 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
166 void *data, int flag)
168 struct lustre_handle lockh;
172 case LDLM_CB_BLOCKING:
173 ldlm_lock2handle(lock, &lockh);
174 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
176 CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc);
180 case LDLM_CB_CANCELING: {
181 struct inode *inode = ll_inode_from_resource_lock(lock);
182 __u64 bits = lock->l_policy_data.l_inodebits.bits;
184 /* Inode is set to lock->l_resource->lr_lvb_inode
185 * for mdc - bug 24555
187 LASSERT(!lock->l_ast_data);
192 /* Invalidate all dentries associated with this inode */
193 LASSERT(ldlm_is_canceling(lock));
195 if (!fid_res_name_eq(ll_inode2fid(inode),
196 &lock->l_resource->lr_name)) {
197 LDLM_ERROR(lock, "data mismatch with object "DFID"(%p)",
198 PFID(ll_inode2fid(inode)), inode);
202 if (bits & MDS_INODELOCK_XATTR) {
203 ll_xattr_cache_destroy(inode);
204 bits &= ~MDS_INODELOCK_XATTR;
207 /* For OPEN locks we differentiate between lock modes
208 * LCK_CR, LCK_CW, LCK_PR - bug 22891
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 "DFID"\n",
261 PFID(ll_inode2fid(inode)));
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 &&
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.
294 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
298 suppgids[0] = ll_i2suppgid(i1);
301 suppgids[1] = ll_i2suppgid(i2);
307 * try to reuse three types of dentry:
308 * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid
309 * by concurrent .revalidate).
310 * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may
311 * be cleared by others calling d_lustre_revalidate).
312 * 3. DISCONNECTED alias.
314 static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
316 struct dentry *alias, *discon_alias, *invalid_alias;
318 if (hlist_empty(&inode->i_dentry))
321 discon_alias = invalid_alias = NULL;
323 ll_lock_dcache(inode);
324 hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
325 LASSERT(alias != dentry);
327 spin_lock(&alias->d_lock);
328 if (alias->d_flags & DCACHE_DISCONNECTED)
329 /* LASSERT(last_discon == NULL); LU-405, bz 20055 */
330 discon_alias = alias;
331 else if (alias->d_parent == dentry->d_parent &&
332 alias->d_name.hash == dentry->d_name.hash &&
333 alias->d_name.len == dentry->d_name.len &&
334 memcmp(alias->d_name.name, dentry->d_name.name,
335 dentry->d_name.len) == 0)
336 invalid_alias = alias;
337 spin_unlock(&alias->d_lock);
342 alias = invalid_alias ?: discon_alias ?: NULL;
344 spin_lock(&alias->d_lock);
346 spin_unlock(&alias->d_lock);
348 ll_unlock_dcache(inode);
354 * Similar to d_splice_alias(), but lustre treats invalid alias
355 * similar to DCACHE_DISCONNECTED, and tries to use it anyway.
357 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de)
363 new = ll_find_alias(inode, de);
373 "Reuse dentry %p inode %p refc %d flags %#x\n",
374 new, d_inode(new), d_count(new), new->d_flags);
382 CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n",
383 de, d_inode(de), d_count(de), de->d_flags);
387 static int ll_lookup_it_finish(struct ptlrpc_request *request,
388 struct lookup_intent *it,
389 struct inode *parent, struct dentry **de)
391 struct inode *inode = NULL;
395 /* NB 1 request reference will be taken away by ll_intent_lock()
398 CDEBUG(D_DENTRY, "it %p it_disposition %x\n", it,
399 it->d.lustre.it_disposition);
400 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
401 rc = ll_prep_inode(&inode, request, (*de)->d_sb, it);
405 ll_set_lock_data(ll_i2sbi(parent)->ll_md_exp, inode, it, &bits);
407 /* We used to query real size from OSTs here, but actually
408 * this is not needed. For stat() calls size would be updated
409 * from subsequent do_revalidate()->ll_inode_revalidate_it() in
411 * vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
412 * Everybody else who needs correct file size would call
413 * ll_glimpse_size or some equivalent themselves anyway.
418 /* Only hash *de if it is unhashed (new dentry).
419 * Atoimc_open may passing hashed dentries for open.
421 if (d_unhashed(*de)) {
422 struct dentry *alias;
424 alias = ll_splice_alias(inode, *de);
430 } else if (!it_disposition(it, DISP_LOOKUP_NEG) &&
431 !it_disposition(it, DISP_OPEN_CREATE)) {
432 /* With DISP_OPEN_CREATE dentry will be
433 * instantiated in ll_create_it.
435 LASSERT(!d_inode(*de));
436 d_instantiate(*de, inode);
439 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
440 /* we have lookup look - unhide dentry */
441 if (bits & MDS_INODELOCK_LOOKUP)
442 d_lustre_revalidate(*de);
443 } else if (!it_disposition(it, DISP_OPEN_CREATE)) {
444 /* If file created on server, don't depend on parent UPDATE
445 * lock to unhide it. It is left hidden and next lookup can
446 * find it in ll_splice_alias.
448 /* Check that parent has UPDATE lock. */
449 struct lookup_intent parent_it = {
451 .d.lustre.it_lock_handle = 0 };
453 if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it,
454 &ll_i2info(parent)->lli_fid, NULL)) {
455 d_lustre_revalidate(*de);
456 ll_intent_release(&parent_it);
461 if (rc != 0 && it->it_op & IT_OPEN)
462 ll_open_cleanup((*de)->d_sb, request);
467 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
468 struct lookup_intent *it, int lookup_flags)
470 struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
471 struct dentry *save = dentry, *retval;
472 struct ptlrpc_request *req = NULL;
474 struct md_op_data *op_data;
478 if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
479 return ERR_PTR(-ENAMETOOLONG);
481 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),intent=%s\n",
482 dentry, PFID(ll_inode2fid(parent)), parent, LL_IT2STR(it));
484 if (d_mountpoint(dentry))
485 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
487 if (!it || it->it_op == IT_GETXATTR)
490 if (it->it_op == IT_GETATTR) {
491 rc = ll_statahead_enter(parent, &dentry, 0);
501 if (it->it_op & IT_CREAT)
502 opc = LUSTRE_OPC_CREATE;
504 opc = LUSTRE_OPC_ANY;
506 op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name,
507 dentry->d_name.len, lookup_flags, opc,
510 return (void *)op_data;
512 /* enforce umask if acl disabled or MDS doesn't support umask */
513 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
514 it->it_create_mode &= ~current_umask();
516 rc = md_intent_lock(ll_i2mdexp(parent), op_data, NULL, 0, it,
517 lookup_flags, &req, ll_md_blocking_ast, 0);
518 ll_finish_md_op_data(op_data);
520 retval = ERR_PTR(rc);
524 rc = ll_lookup_it_finish(req, it, parent, &dentry);
526 ll_intent_release(it);
527 retval = ERR_PTR(rc);
531 inode = d_inode(dentry);
532 if ((it->it_op & IT_OPEN) && inode &&
533 !S_ISREG(inode->i_mode) &&
534 !S_ISDIR(inode->i_mode)) {
535 ll_release_openhandle(inode, it);
537 ll_lookup_finish_locks(it, inode);
545 ptlrpc_req_finished(req);
546 if (it->it_op == IT_GETATTR && (!retval || retval == dentry))
547 ll_statahead_mark(parent, dentry);
551 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
554 struct lookup_intent *itp, it = { .it_op = IT_GETATTR };
557 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),flags=%u\n",
558 dentry, PFID(ll_inode2fid(parent)), parent, flags);
560 /* Optimize away (CREATE && !OPEN). Let .create handle the race. */
561 if ((flags & LOOKUP_CREATE) && !(flags & LOOKUP_OPEN))
564 if (flags & (LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE))
568 de = ll_lookup_it(parent, dentry, itp, 0);
571 ll_intent_release(itp);
577 * For cached negative dentry and new dentry, handle lookup/create/open
580 static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
581 struct file *file, unsigned open_flags,
582 umode_t mode, int *opened)
584 struct lookup_intent *it;
586 long long lookup_flags = LOOKUP_OPEN;
589 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),file %p,open_flags %x,mode %x opened %d\n",
590 dentry, PFID(ll_inode2fid(dir)), dir, file, open_flags, mode,
593 it = kzalloc(sizeof(*it), GFP_NOFS);
598 if (open_flags & O_CREAT) {
599 it->it_op |= IT_CREAT;
600 lookup_flags |= LOOKUP_CREATE;
602 it->it_create_mode = (mode & S_IALLUGO) | S_IFREG;
603 it->it_flags = (open_flags & ~O_ACCMODE) | OPEN_FMODE(open_flags);
605 /* Dentry added to dcache tree in ll_lookup_it */
606 de = ll_lookup_it(dir, dentry, it, lookup_flags);
613 if (it_disposition(it, DISP_OPEN_CREATE)) {
614 /* Dentry instantiated in ll_create_it. */
615 rc = ll_create_it(dir, dentry, mode, it);
617 /* We dget in ll_splice_alias. */
623 *opened |= FILE_CREATED;
625 if (d_really_is_positive(dentry) && it_disposition(it, DISP_OPEN_OPEN)) {
627 if (S_ISFIFO(d_inode(dentry)->i_mode)) {
628 /* We cannot call open here as it would
631 if (it_disposition(it, DISP_ENQ_OPEN_REF))
633 (struct ptlrpc_request *)
634 it->d.lustre.it_data);
635 rc = finish_no_open(file, de);
637 file->private_data = it;
638 rc = finish_open(file, dentry, NULL, opened);
639 /* We dget in ll_splice_alias. finish_open takes
640 * care of dget for fd open.
646 rc = finish_no_open(file, de);
651 ll_intent_release(it);
657 /* We depend on "mode" being set with the proper file type/umask by now */
658 static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
660 struct inode *inode = NULL;
661 struct ptlrpc_request *request = NULL;
662 struct ll_sb_info *sbi = ll_i2sbi(dir);
665 LASSERT(it && it->d.lustre.it_disposition);
667 LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
668 request = it->d.lustre.it_data;
669 it_clear_disposition(it, DISP_ENQ_CREATE_REF);
670 rc = ll_prep_inode(&inode, request, dir->i_sb, it);
676 LASSERT(hlist_empty(&inode->i_dentry));
678 /* We asked for a lock on the directory, but were granted a
679 * lock on the inode. Since we finally have an inode pointer,
680 * stuff it in the lock.
682 CDEBUG(D_DLMTRACE, "setting l_ast_data to inode "DFID"(%p)\n",
683 PFID(ll_inode2fid(dir)), inode);
684 ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
686 ptlrpc_req_finished(request);
691 * By the time this is called, we already have created the directory cache
692 * entry for the new file, but it is so far negative - it has no inode.
694 * We defer creating the OBD object(s) until open, to keep the intent and
695 * non-intent code paths similar, and also because we do not have the MDS
696 * inode number before calling ll_create_node() (which is needed for LOV),
697 * so we would need to do yet another RPC to the MDS to store the LOV EA
698 * data on the MDS. If needed, we would pass the PACKED lmm as data and
699 * lmm_size in datalen (the MDS still has code which will handle that).
701 * If the create succeeds, we fill in the inode information
702 * with d_instantiate().
704 static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode,
705 struct lookup_intent *it)
710 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p), intent=%s\n",
711 dentry, PFID(ll_inode2fid(dir)), dir, LL_IT2STR(it));
713 rc = it_open_error(DISP_OPEN_CREATE, it);
717 inode = ll_create_node(dir, it);
719 return PTR_ERR(inode);
721 d_instantiate(dentry, inode);
725 static void ll_update_times(struct ptlrpc_request *request,
728 struct mdt_body *body = req_capsule_server_get(&request->rq_pill,
732 if (body->valid & OBD_MD_FLMTIME &&
733 body->mtime > LTIME_S(inode->i_mtime)) {
734 CDEBUG(D_INODE, "setting fid "DFID" mtime from %lu to %llu\n",
735 PFID(ll_inode2fid(inode)), LTIME_S(inode->i_mtime),
737 LTIME_S(inode->i_mtime) = body->mtime;
739 if (body->valid & OBD_MD_FLCTIME &&
740 body->ctime > LTIME_S(inode->i_ctime))
741 LTIME_S(inode->i_ctime) = body->ctime;
744 static int ll_new_node(struct inode *dir, struct dentry *dentry,
745 const char *tgt, int mode, int rdev,
748 struct ptlrpc_request *request = NULL;
749 struct md_op_data *op_data;
750 struct inode *inode = NULL;
751 struct ll_sb_info *sbi = ll_i2sbi(dir);
756 tgt_len = strlen(tgt) + 1;
758 op_data = ll_prep_md_op_data(NULL, dir, NULL,
762 if (IS_ERR(op_data)) {
763 err = PTR_ERR(op_data);
767 err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode,
768 from_kuid(&init_user_ns, current_fsuid()),
769 from_kgid(&init_user_ns, current_fsgid()),
770 cfs_curproc_cap_pack(), rdev, &request);
771 ll_finish_md_op_data(op_data);
775 ll_update_times(request, dir);
777 err = ll_prep_inode(&inode, request, dir->i_sb, NULL);
781 d_instantiate(dentry, inode);
783 ptlrpc_req_finished(request);
788 static int ll_mknod(struct inode *dir, struct dentry *dchild,
789 umode_t mode, dev_t rdev)
793 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p) mode %o dev %x\n",
794 dchild, PFID(ll_inode2fid(dir)), dir, mode,
795 old_encode_dev(rdev));
797 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
798 mode &= ~current_umask();
800 switch (mode & S_IFMT) {
802 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
808 err = ll_new_node(dir, dchild, NULL, mode,
809 old_encode_dev(rdev),
820 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD, 1);
826 * Plain create. Intent create is handled in atomic_open.
828 static int ll_create_nd(struct inode *dir, struct dentry *dentry,
829 umode_t mode, bool want_excl)
833 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p), flags=%u, excl=%d\n",
834 dentry, PFID(ll_inode2fid(dir)), dir, mode, want_excl);
836 rc = ll_mknod(dir, dentry, mode, 0);
838 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
840 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, unhashed %d\n",
841 dentry, d_unhashed(dentry));
846 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
848 struct mdt_body *body;
849 struct lov_mds_md *eadata;
850 struct lov_stripe_md *lsm = NULL;
851 struct obd_trans_info oti = { 0 };
855 /* req is swabbed so this is safe */
856 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
857 if (!(body->valid & OBD_MD_FLEASIZE))
860 if (body->eadatasize == 0) {
861 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
866 /* The MDS sent back the EA because we unlinked the last reference
867 * to this file. Use this EA to unlink the objects on the OST.
868 * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
869 * check it is complete and sensible.
871 eadata = req_capsule_server_sized_get(&request->rq_pill, &RMF_MDT_MD,
875 rc = obd_unpackmd(ll_i2dtexp(dir), &lsm, eadata, body->eadatasize);
877 CERROR("obd_unpackmd: %d\n", rc);
880 LASSERT(rc >= sizeof(*lsm));
882 oa = kmem_cache_zalloc(obdo_cachep, GFP_NOFS);
888 oa->o_oi = lsm->lsm_oi;
889 oa->o_mode = body->mode & S_IFMT;
890 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
892 if (body->valid & OBD_MD_FLCOOKIE) {
893 oa->o_valid |= OBD_MD_FLCOOKIE;
895 req_capsule_server_sized_get(&request->rq_pill,
897 sizeof(struct llog_cookie) *
898 lsm->lsm_stripe_count);
899 if (!oti.oti_logcookies) {
900 oa->o_valid &= ~OBD_MD_FLCOOKIE;
901 body->valid &= ~OBD_MD_FLCOOKIE;
905 rc = obd_destroy(NULL, ll_i2dtexp(dir), oa, lsm, &oti,
908 CERROR("obd destroy objid "DOSTID" error %d\n",
909 POSTID(&lsm->lsm_oi), rc);
911 obd_free_memmd(ll_i2dtexp(dir), &lsm);
912 kmem_cache_free(obdo_cachep, oa);
917 /* ll_unlink() doesn't update the inode with the new link count.
918 * Instead, ll_ddelete() and ll_d_iput() will update it based upon if there
919 * is any lock existing. They will recycle dentries and inodes based upon locks
922 static int ll_unlink(struct inode *dir, struct dentry *dchild)
924 struct ptlrpc_request *request = NULL;
925 struct md_op_data *op_data;
928 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
929 dchild, dir->i_ino, dir->i_generation, dir);
931 op_data = ll_prep_md_op_data(NULL, dir, NULL,
934 0, LUSTRE_OPC_ANY, NULL);
936 return PTR_ERR(op_data);
938 if (dchild && dchild->d_inode)
939 op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
941 op_data->op_fid2 = op_data->op_fid3;
942 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
943 ll_finish_md_op_data(op_data);
947 ll_update_times(request, dir);
948 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1);
950 rc = ll_objects_destroy(request, dir);
952 ptlrpc_req_finished(request);
956 static int ll_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
960 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir"DFID"(%p)\n",
961 dentry, PFID(ll_inode2fid(dir)), dir);
963 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
964 mode &= ~current_umask();
965 mode = (mode & (S_IRWXUGO|S_ISVTX)) | S_IFDIR;
966 err = ll_new_node(dir, dentry, NULL, mode, 0, LUSTRE_OPC_MKDIR);
969 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR, 1);
974 static int ll_rmdir(struct inode *dir, struct dentry *dchild)
976 struct ptlrpc_request *request = NULL;
977 struct md_op_data *op_data;
980 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p)\n",
981 dchild, PFID(ll_inode2fid(dir)), dir);
983 op_data = ll_prep_md_op_data(NULL, dir, NULL,
986 S_IFDIR, LUSTRE_OPC_ANY, NULL);
988 return PTR_ERR(op_data);
990 if (dchild && dchild->d_inode)
991 op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
993 op_data->op_fid2 = op_data->op_fid3;
994 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
995 ll_finish_md_op_data(op_data);
997 ll_update_times(request, dir);
998 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
1001 ptlrpc_req_finished(request);
1005 static int ll_symlink(struct inode *dir, struct dentry *dentry,
1006 const char *oldname)
1010 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),target=%.*s\n",
1011 dentry, PFID(ll_inode2fid(dir)), dir, 3000, oldname);
1013 err = ll_new_node(dir, dentry, oldname, S_IFLNK | S_IRWXUGO,
1014 0, LUSTRE_OPC_SYMLINK);
1017 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK, 1);
1022 static int ll_link(struct dentry *old_dentry, struct inode *dir,
1023 struct dentry *new_dentry)
1025 struct inode *src = d_inode(old_dentry);
1026 struct ll_sb_info *sbi = ll_i2sbi(dir);
1027 struct ptlrpc_request *request = NULL;
1028 struct md_op_data *op_data;
1031 CDEBUG(D_VFSTRACE, "VFS Op: inode="DFID"(%p), dir="DFID"(%p), target=%pd\n",
1032 PFID(ll_inode2fid(src)), src, PFID(ll_inode2fid(dir)), dir,
1035 op_data = ll_prep_md_op_data(NULL, src, dir, new_dentry->d_name.name,
1036 new_dentry->d_name.len,
1037 0, LUSTRE_OPC_ANY, NULL);
1038 if (IS_ERR(op_data))
1039 return PTR_ERR(op_data);
1041 err = md_link(sbi->ll_md_exp, op_data, &request);
1042 ll_finish_md_op_data(op_data);
1046 ll_update_times(request, dir);
1047 ll_stats_ops_tally(sbi, LPROC_LL_LINK, 1);
1049 ptlrpc_req_finished(request);
1053 static int ll_rename(struct inode *src, struct dentry *src_dchild,
1054 struct inode *tgt, struct dentry *tgt_dchild)
1056 struct ptlrpc_request *request = NULL;
1057 struct ll_sb_info *sbi = ll_i2sbi(src);
1058 struct md_op_data *op_data;
1062 "VFS Op:oldname=%pd, src_dir="DFID"(%p), newname=%pd, tgt_dir="DFID"(%p)\n",
1063 src_dchild, PFID(ll_inode2fid(src)), src,
1064 tgt_dchild, PFID(ll_inode2fid(tgt)), tgt);
1066 op_data = ll_prep_md_op_data(NULL, src, tgt, NULL, 0, 0,
1067 LUSTRE_OPC_ANY, NULL);
1068 if (IS_ERR(op_data))
1069 return PTR_ERR(op_data);
1071 if (src_dchild && src_dchild->d_inode)
1072 op_data->op_fid3 = *ll_inode2fid(src_dchild->d_inode);
1073 if (tgt_dchild && tgt_dchild->d_inode)
1074 op_data->op_fid4 = *ll_inode2fid(tgt_dchild->d_inode);
1076 err = md_rename(sbi->ll_md_exp, op_data,
1077 src_dchild->d_name.name,
1078 src_dchild->d_name.len,
1079 tgt_dchild->d_name.name,
1080 tgt_dchild->d_name.len, &request);
1081 ll_finish_md_op_data(op_data);
1083 ll_update_times(request, src);
1084 ll_update_times(request, tgt);
1085 ll_stats_ops_tally(sbi, LPROC_LL_RENAME, 1);
1086 err = ll_objects_destroy(request, src);
1089 ptlrpc_req_finished(request);
1091 d_move(src_dchild, tgt_dchild);
1095 const struct inode_operations ll_dir_inode_operations = {
1097 .atomic_open = ll_atomic_open,
1098 .lookup = ll_lookup_nd,
1099 .create = ll_create_nd,
1100 /* We need all these non-raw things for NFSD, to not patch it. */
1101 .unlink = ll_unlink,
1104 .symlink = ll_symlink,
1106 .rename = ll_rename,
1107 .setattr = ll_setattr,
1108 .getattr = ll_getattr,
1109 .permission = ll_inode_permission,
1110 .setxattr = ll_setxattr,
1111 .getxattr = ll_getxattr,
1112 .listxattr = ll_listxattr,
1113 .removexattr = ll_removexattr,
1114 .get_acl = ll_get_acl,
1117 const struct inode_operations ll_special_inode_operations = {
1118 .setattr = ll_setattr,
1119 .getattr = ll_getattr,
1120 .permission = ll_inode_permission,
1121 .setxattr = ll_setxattr,
1122 .getxattr = ll_getxattr,
1123 .listxattr = ll_listxattr,
1124 .removexattr = ll_removexattr,
1125 .get_acl = ll_get_acl,