1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * derived in small part from linux/fs/ext2/namei.c
23 * Copyright (C) 1991, 1992 Linus Torvalds
25 * Big-endian to little-endian byte-swapping/bitmaps by
26 * David S. Miller (davem@caip.rutgers.edu), 1995
27 * Directory entry file type support and forward compatibility hooks
28 * for B-tree directories by Theodore Ts'o (tytso@mit.edu), 1998
32 #include <linux/sched.h>
34 #include <linux/smp_lock.h>
35 #include <linux/quotaops.h>
36 #include <linux/highmem.h>
37 #include <linux/pagemap.h>
39 #define DEBUG_SUBSYSTEM S_LLITE
41 #include <linux/obd_support.h>
42 #include <linux/lustre_lite.h>
43 #include <linux/lustre_dlm.h>
46 extern void ll_set_dd(struct dentry *de);
49 extern void ll_change_inode(struct inode *inode);
50 extern int ll_setattr(struct dentry *de, struct iattr *attr);
53 extern int ll_add_link (struct dentry *dentry, struct inode *inode);
54 obd_id ll_inode_by_name(struct inode * dir, struct dentry *dentry, int *typ);
55 int ext2_make_empty(struct inode *inode, struct inode *parent);
56 struct ext2_dir_entry_2 * ext2_find_entry (struct inode * dir,
57 struct dentry *dentry, struct page ** res_page);
58 int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page );
59 int ext2_empty_dir (struct inode * inode);
60 struct ext2_dir_entry_2 * ext2_dotdot (struct inode *dir, struct page **p);
61 void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
62 struct page *page, struct inode *inode);
65 * Couple of helper functions - make the code slightly cleaner.
67 static inline void ext2_inc_count(struct inode *inode)
72 /* postpone the disk update until the inode really goes away */
73 static inline void ext2_dec_count(struct inode *inode)
77 static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
80 err = ll_add_link(dentry, inode);
82 d_instantiate(dentry, inode);
85 ext2_dec_count(inode);
92 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
93 static int ll_find_inode(struct inode *inode, unsigned long ino, void *opaque)
95 static int ll_test_inode(struct inode *inode, void *opaque)
98 struct ll_read_inode2_cookie *lic = opaque;
99 struct mds_body *body = lic->lic_body;
101 if (inode->i_generation != lic->lic_body->generation)
104 /* Apply the attributes in 'opaque' to this inode */
105 ll_update_inode(inode, body, lic->lic_lmm);
110 extern struct dentry_operations ll_d_ops;
112 int ll_unlock(__u32 mode, struct lustre_handle *lockh)
116 ldlm_lock_decref(lockh, mode);
121 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
122 extern int ll_read_inode2(struct inode *inode, void *opaque);
123 struct inode *ll_iget(struct super_block *sb, ino_t hash,
124 struct ll_read_inode2_cookie *lic)
129 inode = iget5_locked(sb, hash, ll_test_inode, ll_read_inode2, lic);
132 return ERR_PTR(-ENOMEM);
134 if (inode->i_state & I_NEW)
135 unlock_new_inode(inode);
137 // XXX Coda always fills inodes, should Lustre?
141 struct inode *ll_iget(struct super_block *sb, ino_t hash,
142 struct ll_read_inode2_cookie *lic)
146 inode = iget4(sb, hash, ll_find_inode, lic);
151 static int ll_intent_to_lock_mode(struct lookup_intent *it)
153 /* CREAT needs to be tested before open (both could be set) */
154 if (it->it_op & (IT_CREAT | IT_SETATTR))
156 else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP))
163 int ll_it_open_error(int phase, struct lookup_intent *it)
165 if (it->it_disposition & IT_OPEN_OPEN) {
166 if (phase == IT_OPEN_OPEN)
167 return it->it_status;
172 if (it->it_disposition & IT_OPEN_CREATE) {
173 if (phase == IT_OPEN_CREATE)
174 return it->it_status;
179 if (it->it_disposition & IT_OPEN_LOOKUP) {
180 if (phase == IT_OPEN_LOOKUP)
181 return it->it_status;
189 #define IT_ENQ_COMPLETE (1<<16)
191 int ll_intent_lock(struct inode *parent, struct dentry **de,
192 struct lookup_intent *it, intent_finish_cb intent_finish)
194 struct dentry *dentry = *de;
195 struct ll_sb_info *sbi = ll_i2sbi(parent);
196 struct lustre_handle lockh;
197 struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
198 struct ptlrpc_request *request = NULL;
200 int rc = 0, datalen = 0, offset, flag = 0;
207 CDEBUG(D_INFO, "name: %*s, intent: %s\n", dentry->d_name.len,
208 dentry->d_name.name, ldlm_it2str(it->it_op));
210 if (dentry->d_name.len > EXT2_NAME_LEN)
211 RETURN(-ENAMETOOLONG);
213 if (!(it->it_disposition & IT_ENQ_COMPLETE)) {
214 rc = mdc_enqueue(&sbi->ll_mdc_conn, LDLM_PLAIN, it,
215 ll_intent_to_lock_mode(it), parent, dentry,
216 &lockh, data, datalen, parent,
220 memcpy(it->it_lock_handle, &lockh, sizeof(lockh));
223 request = (struct ptlrpc_request *)it->it_data;
225 /* non-zero it_disposition indicates that the server performed the
226 * intent on our behalf. */
227 if (it->it_disposition) {
228 struct mds_body *mds_body;
231 /* This long block is all about fixing up the local
232 * state so that it is correct as of the moment
233 * _before_ the operation was applied; that way, the
234 * VFS will think that everything is normal and call
235 * Lustre's regular FS function.
237 * If we're performing a creation, that means that unless the
238 * creation failed with EEXIST, we should fake up a negative
239 * dentry. Likewise for the target of a hard link.
241 * For everything else, we want to lookup to succeed. */
243 /* One additional note: if CREATE/MKDIR/etc succeeded,
244 * we add an extra reference to the request because we
245 * need to keep it around until ll_create gets called.
246 * For anything else which results in
247 * LL_LOOKUP_POSITIVE, we can do the iget()
248 * immediately with the contents of the reply (in the
249 * intent_finish callback). In the create case,
250 * however, we need to wait until ll_create_node to do
251 * the iget() or the VFS will abort with -EEXISTS.
255 mds_body = lustre_msg_buf(request->rq_repmsg, offset);
256 ino = mds_body->fid1.id;
257 mode = mds_body->mode;
259 /*We were called from revalidate2: did we find the same inode?*/
260 if ((*de)->d_inode &&
261 (ino != (*de)->d_inode->i_ino ||
262 mds_body->fid1.generation != (*de)->d_inode->i_generation)) {
263 it->it_disposition |= IT_ENQ_COMPLETE;
267 /* If we're doing an IT_OPEN which did not result in an actual
268 * successful open, then we need to remove the bit which saves
269 * this request for unconditional replay. */
270 if (it->it_op & IT_OPEN &&
271 (!(it->it_disposition & IT_OPEN_OPEN) ||
273 request->rq_flags &= ~PTL_RPC_FL_REPLAY;
275 if (it->it_op & IT_CREAT) {
276 mdc_store_inode_generation(request, 2, 1);
277 /* The server will return to us, in it_disposition, an
278 * indication of exactly what it_status refers to.
280 * If IT_OPEN_OPEN is set, then it_status refers to the
281 * open() call, otherwise if IT_OPEN_CREATE is set, then
282 * it status is the creation failure mode. In either
283 * case, one of IT_OPEN_NEG or IT_OPEN_POS will be set,
284 * indicating whether the child lookup was successful.
286 * Else, if IT_OPEN_LOOKUP then it_status is the rc
287 * of the child lookup.
289 * Finally, if none of the bits are set, then the
290 * failure occurred while looking up the parent. */
291 rc = ll_it_open_error(IT_OPEN_LOOKUP, it);
295 if (it->it_disposition & IT_OPEN_CREATE)
296 ptlrpc_request_addref(request);
298 if (it->it_disposition & IT_OPEN_NEG)
299 flag = LL_LOOKUP_NEGATIVE;
301 flag = LL_LOOKUP_POSITIVE;
302 } else if (it->it_op == IT_OPEN) {
303 LASSERT(!(it->it_disposition & IT_OPEN_CREATE));
305 rc = ll_it_open_error(IT_OPEN_LOOKUP, it);
309 if (it->it_disposition & IT_OPEN_OPEN)
310 ptlrpc_request_addref(request);
312 if (it->it_disposition & IT_OPEN_NEG)
313 flag = LL_LOOKUP_NEGATIVE;
315 flag = LL_LOOKUP_POSITIVE;
316 } else if (it->it_op & (IT_GETATTR | IT_SETATTR | IT_LOOKUP |
318 /* For check ops, we want the lookup to succeed */
321 flag = LL_LOOKUP_NEGATIVE;
323 flag = LL_LOOKUP_POSITIVE;
330 LBUG(); /* For the moment, no non-intent locks */
332 /* it_disposition == 0 indicates that it just did a simple lock
333 * request, for which we are very thankful. move along with
334 * the local lookup then. */
336 //memcpy(&lli->lli_intent_lock_handle, &lockh, sizeof(lockh));
339 ino = ll_inode_by_name(parent, dentry, &mode);
341 CERROR("inode %*s not found by name\n",
342 dentry->d_name.len, dentry->d_name.name);
343 GOTO(drop_lock, rc = -ENOENT);
346 valid = OBD_MD_FLNOTOBD;
349 datalen = obd_size_wiremd(&sbi->ll_osc_conn, NULL),
350 valid |= OBD_MD_FLEASIZE;
352 valid |= OBD_MD_FLBLOCKS;
355 rc = mdc_getattr(&sbi->ll_mdc_conn, ino, mode, valid,
358 CERROR("failure %d inode "LPX64"\n", rc, ino);
359 GOTO(drop_req, rc = -abs(rc));
363 if (intent_finish != NULL) {
364 rc = intent_finish(flag, request, de, it, offset, ino);
365 dentry = *de; /* intent_finish may change *de */
367 ptlrpc_req_finished(request);
370 /* This places the intent in the dentry so that the vfs_xxx
371 * operation can lay its hands on it; but that is not always
372 * needed... (we need to save it in the GETATTR case for the
373 * benefit of ll_inode_revalidate -phil) */
374 if (it->it_op & (IT_OPEN | IT_GETATTR))
375 LL_SAVE_INTENT(dentry, it);
378 "D_IT dentry %p fsdata %p intent: %s status %d\n",
379 dentry, ll_d2d(dentry), ldlm_it2str(it->it_op),
382 if (it->it_op == IT_LOOKUP)
383 ll_intent_release(dentry, it);
388 ptlrpc_req_finished(request);
390 #warning FIXME: must release lock here
394 /* Search "inode"'s alias list for a dentry that has the same name and parent as
395 * de. If found, return it. If not found, return de. */
396 struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
398 struct list_head *tmp;
400 spin_lock(&dcache_lock);
401 list_for_each(tmp, &inode->i_dentry) {
402 struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
404 /* We are called here with 'de' already on the aliases list. */
410 if (dentry->d_parent != de->d_parent)
413 if (dentry->d_name.len != de->d_name.len)
416 if (memcmp(dentry->d_name.name, de->d_name.name,
417 de->d_name.len) != 0)
420 if (!list_empty(&dentry->d_lru))
421 list_del_init(&dentry->d_lru);
423 list_del_init(&dentry->d_hash);
424 spin_unlock(&dcache_lock);
426 atomic_inc(&dentry->d_count);
428 dentry->d_flags &= ~DCACHE_LUSTRE_INVALID;
432 spin_unlock(&dcache_lock);
438 lookup2_finish(int flag, struct ptlrpc_request *request, struct dentry **de,
439 struct lookup_intent *it, int offset, obd_id ino)
441 struct dentry *dentry = *de, *saved = *de;
442 struct inode *inode = NULL;
443 struct ll_read_inode2_cookie lic = {.lic_body = NULL, .lic_lmm = NULL};
445 if (!(flag & LL_LOOKUP_NEGATIVE)) {
447 lic.lic_body = lustre_msg_buf(request->rq_repmsg, offset);
449 if (S_ISREG(lic.lic_body->mode) &&
450 lic.lic_body->valid & OBD_MD_FLEASIZE) {
451 LASSERT(request->rq_repmsg->bufcount > offset);
452 lic.lic_lmm = lustre_msg_buf(request->rq_repmsg,
458 /* No rpc's happen during iget4, -ENOMEM's are possible */
459 inode = ll_iget(dentry->d_sb, ino, &lic);
461 /* XXX make sure that request is freed in this case;
462 * I think it is, but double-check refcounts. -phil */
466 dentry = *de = ll_find_alias(inode, dentry);
468 /* We asked for a lock on the directory, and may have been
469 * granted a lock on the inode. Just in case, fixup the data
471 mdc_lock_set_inode((struct lustre_handle *)it->it_lock_handle,
477 ptlrpc_req_finished(request);
479 dentry->d_op = &ll_d_ops;
483 d_add(dentry, inode);
488 static struct dentry *ll_lookup2(struct inode *parent, struct dentry *dentry,
489 struct lookup_intent *it)
491 struct dentry *save = dentry;
495 if (it && it->it_op == IT_TRUNC)
496 it->it_op = IT_SETATTR;
498 rc = ll_intent_lock(parent, &dentry, it, lookup2_finish);
500 CDEBUG(D_INFO, "ll_intent_lock: %d\n", rc);
510 /* We depend on "mode" being set with the proper file type/umask by now */
511 static struct inode *ll_create_node(struct inode *dir, const char *name,
512 int namelen, const void *data, int datalen,
513 int mode, __u64 extra,
514 struct lookup_intent *it)
517 struct ptlrpc_request *request = NULL;
518 struct mds_body *body;
519 time_t time = CURRENT_TIME;
520 struct ll_sb_info *sbi = ll_i2sbi(dir);
521 struct ll_read_inode2_cookie lic = { .lic_lmm = NULL, };
524 if (it && it->it_disposition) {
525 ll_invalidate_inode_pages(dir);
526 request = it->it_data;
527 body = lustre_msg_buf(request->rq_repmsg, 1);
529 int gid = current->fsgid;
532 if (dir->i_mode & S_ISGID) {
538 rc = mdc_create(&sbi->ll_mdc_conn, dir, name, namelen,
539 data, datalen, mode, current->fsuid, gid,
540 time, extra, &request);
545 body = lustre_msg_buf(request->rq_repmsg, 0);
550 inode = ll_iget(dir->i_sb, body->ino, &lic);
552 int rc = PTR_ERR(inode);
553 CERROR("new_inode -fatal: rc %d\n", rc);
558 if (!list_empty(&inode->i_dentry)) {
559 CERROR("new_inode -fatal: inode %d, ct %d lnk %d\n",
560 body->ino, atomic_read(&inode->i_count),
564 inode = ERR_PTR(-EIO);
568 if (it && it->it_disposition) {
569 /* We asked for a lock on the directory, but were
570 * granted a lock on the inode. Since we finally have
571 * an inode pointer, stuff it in the lock. */
572 mdc_lock_set_inode((struct lustre_handle *)it->it_lock_handle,
578 ptlrpc_req_finished(request);
582 static int ll_mdc_unlink(struct inode *dir, struct inode *child, __u32 mode,
583 const char *name, int len)
585 struct ptlrpc_request *request = NULL;
586 struct ll_sb_info *sbi = ll_i2sbi(dir);
587 struct mds_body *body;
588 struct lov_stripe_md *lsm = NULL;
589 struct lustre_handle lockh;
590 struct lookup_intent it = { .it_op = IT_UNLINK };
593 struct mdc_unlink_data data;
598 data.unl_mode = mode;
599 data.unl_name = name;
602 err = mdc_enqueue(&sbi->ll_mdc_conn, LDLM_PLAIN, &it, LCK_EX, dir,
603 NULL, &lockh, NULL, 0, &data, sizeof(data));
604 mdc_put_rpc_lock(&mdc_rpc_lock, &it);
605 request = (struct ptlrpc_request *)it.it_data;
609 GOTO(out, err = it.it_status);
612 body = lustre_msg_buf(request->rq_repmsg, 1);
613 LASSERT(body != NULL);
614 if (!(body->valid & OBD_MD_FLEASIZE))
617 /* The MDS sent back the EA because we unlinked the last reference
618 * to this file. Use this EA to unlink the objects on the OST */
619 err = obd_unpackmd(ll_i2obdconn(dir), &lsm,
620 lustre_msg_buf(request->rq_repmsg, 2));
622 CERROR("obd_unpackmd: %d\n", err);
626 GOTO(out_unlock, err = -ENOMEM);
628 oa->o_id = lsm->lsm_object_id;
629 oa->o_mode = body->mode & S_IFMT;
630 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
632 err = obd_destroy(ll_i2obdconn(dir), oa, lsm, NULL);
635 CERROR("obd destroy objid 0x"LPX64" error %d\n",
636 lsm->lsm_object_id, err);
638 obd_free_memmd(ll_i2obdconn(dir), &lsm);
640 ldlm_lock_decref_and_cancel(&lockh, LCK_EX);
642 ptlrpc_req_finished(request);
647 * By the time this is called, we already have created the directory cache
648 * entry for the new file, but it is so far negative - it has no inode.
650 * We defer creating the OBD object(s) until open, to keep the intent and
651 * non-intent code paths similar, and also because we do not have the MDS
652 * inode number before calling ll_create_node() (which is needed for LOV),
653 * so we would need to do yet another RPC to the MDS to store the LOV EA
654 * data on the MDS. If needed, we would pass the PACKED lmm as data and
655 * lmm_size in datalen (the MDS still has code which will handle that).
657 * If the create succeeds, we fill in the inode information
658 * with d_instantiate().
660 static int ll_create(struct inode *dir, struct dentry *dentry, int mode)
662 struct lookup_intent *it;
669 rc = ll_it_open_error(IT_OPEN_CREATE, it);
671 LL_GET_INTENT(dentry, it);
672 ptlrpc_req_finished(it->it_data);
676 inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
677 NULL, 0, mode, 0, it);
680 LL_GET_INTENT(dentry, it);
681 RETURN(PTR_ERR(inode));
684 /* no directory data updates when intents rule */
685 if (it && it->it_disposition) {
686 d_instantiate(dentry, inode);
690 rc = ext2_add_nondir(dentry, inode);
694 static int ll_mknod2(struct inode *dir, const char *name, int len, int mode,
697 struct ptlrpc_request *request = NULL;
698 time_t time = CURRENT_TIME;
699 struct ll_sb_info *sbi = ll_i2sbi(dir);
703 if (dir->i_nlink >= EXT2_LINK_MAX)
706 mode &= ~current->fs->umask;
708 switch (mode & S_IFMT) {
709 case 0: case S_IFREG:
710 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
711 case S_IFCHR: case S_IFBLK:
712 case S_IFIFO: case S_IFSOCK:
713 err = mdc_create(&sbi->ll_mdc_conn, dir, name, len, NULL, 0,
714 mode, current->fsuid, current->fsgid, time,
716 ptlrpc_req_finished(request);
727 static int ll_mknod(struct inode *dir, struct dentry *dentry, int mode,
730 struct lookup_intent *it;
734 LL_GET_INTENT(dentry, it);
736 if ((mode & S_IFMT) == 0)
738 inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
739 NULL, 0, mode, rdev, it);
742 RETURN(PTR_ERR(inode));
744 /* no directory data updates when intents rule */
745 if (it && it->it_disposition)
746 d_instantiate(dentry, inode);
748 rc = ext2_add_nondir(dentry, inode);
753 static int ll_symlink2(struct inode *dir, const char *name, int len,
756 struct ptlrpc_request *request = NULL;
757 time_t time = CURRENT_TIME;
758 struct ll_sb_info *sbi = ll_i2sbi(dir);
762 if (dir->i_nlink >= EXT2_LINK_MAX)
765 err = mdc_create(&sbi->ll_mdc_conn, dir, name, len,
766 tgt, strlen(tgt) + 1, S_IFLNK | S_IRWXUGO,
767 current->fsuid, current->fsgid, time, 0, &request);
768 ptlrpc_req_finished(request);
772 static int ll_symlink(struct inode *dir, struct dentry *dentry,
775 struct lookup_intent *it;
776 unsigned l = strlen(symname) + 1;
778 struct ll_inode_info *lli;
782 LL_GET_INTENT(dentry, it);
784 inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
785 symname, l, S_IFLNK | S_IRWXUGO, 0, it);
787 RETURN(PTR_ERR(inode));
789 lli = ll_i2info(inode);
791 OBD_ALLOC(lli->lli_symlink_name, l);
792 /* this _could_ be a non-fatal error, since the symlink is already
793 * stored on the MDS by this point, and we can re-get it in readlink.
795 if (!lli->lli_symlink_name)
798 memcpy(lli->lli_symlink_name, symname, l);
799 inode->i_size = l - 1;
801 /* no directory data updates when intents rule */
802 if (it && it->it_disposition)
803 d_instantiate(dentry, inode);
805 err = ext2_add_nondir(dentry, inode);
810 static int ll_link2(struct inode *src, struct inode *dir,
811 const char *name, int len)
813 struct ptlrpc_request *request = NULL;
815 struct ll_sb_info *sbi = ll_i2sbi(dir);
819 err = mdc_link(&sbi->ll_mdc_conn, src, dir, name, len, &request);
820 ptlrpc_req_finished(request);
825 static int ll_link(struct dentry *old_dentry, struct inode * dir,
826 struct dentry *dentry)
828 struct lookup_intent *it;
829 struct inode *inode = old_dentry->d_inode;
832 LL_GET_INTENT(dentry, it);
834 if (it && it->it_disposition) {
836 RETURN(it->it_status);
837 inode->i_ctime = CURRENT_TIME;
838 ext2_inc_count(inode);
839 atomic_inc(&inode->i_count);
840 d_instantiate(dentry, inode);
841 ll_invalidate_inode_pages(dir);
845 if (S_ISDIR(inode->i_mode))
848 if (inode->i_nlink >= EXT2_LINK_MAX)
851 rc = ll_link2(old_dentry->d_inode, dir,
852 dentry->d_name.name, dentry->d_name.len);
856 inode->i_ctime = CURRENT_TIME;
857 ext2_inc_count(inode);
858 atomic_inc(&inode->i_count);
860 return ext2_add_nondir(dentry, inode);
863 static int ll_mkdir2(struct inode *dir, const char *name, int len, int mode)
865 struct ptlrpc_request *request = NULL;
866 time_t time = CURRENT_TIME;
867 struct ll_sb_info *sbi = ll_i2sbi(dir);
871 if (dir->i_nlink >= EXT2_LINK_MAX)
874 mode = (mode & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
875 err = mdc_create(&sbi->ll_mdc_conn, dir, name, len, NULL, 0,
876 mode, current->fsuid, current->fsgid,
878 ptlrpc_req_finished(request);
883 static int ll_mkdir(struct inode *dir, struct dentry *dentry, int mode)
885 struct lookup_intent *it;
886 struct inode * inode;
890 LL_GET_INTENT(dentry, it);
892 if (dir->i_nlink >= EXT2_LINK_MAX)
896 inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
897 NULL, 0, S_IFDIR | mode, 0, it);
898 err = PTR_ERR(inode);
902 err = ext2_make_empty(inode, dir);
906 /* no directory data updates when intents rule */
907 if (!it || !it->it_disposition) {
908 /* XXX FIXME This code needs re-checked for non-intents */
909 ext2_inc_count(inode);
910 err = ll_add_link(dentry, inode);
915 d_instantiate(dentry, inode);
921 ext2_dec_count(inode);
922 ext2_dec_count(inode);
931 static int ll_rmdir2(struct inode *dir, const char *name, int len)
936 rc = ll_mdc_unlink(dir, NULL, S_IFDIR, name, len);
940 static int ll_unlink2(struct inode *dir, const char *name, int len)
945 rc = ll_mdc_unlink(dir, NULL, S_IFREG, name, len);
949 static int ll_common_unlink(struct inode *dir, struct dentry *dentry,
950 struct lookup_intent *it, __u32 mode)
952 struct inode *inode = dentry->d_inode;
953 struct ext2_dir_entry_2 * de;
958 if (it && it->it_disposition) {
960 ll_invalidate_inode_pages(dir);
966 de = ext2_find_entry(dir, dentry, &page);
968 GOTO(out, rc = -ENOENT);
969 rc = ll_mdc_unlink(dir, dentry->d_inode, mode,
970 dentry->d_name.name, dentry->d_name.len);
974 rc = ext2_delete_entry(de, page);
978 /* AED: not sure if needed - directory lock revocation should do it
979 * in the case where the client has cached it for non-intent ops.
981 ll_invalidate_inode_pages(dir);
983 inode->i_ctime = dir->i_ctime;
986 ext2_dec_count(inode);
991 static int ll_unlink(struct inode *dir, struct dentry *dentry)
993 struct lookup_intent * it;
996 LL_GET_INTENT(dentry, it);
998 RETURN(ll_common_unlink(dir, dentry, it, S_IFREG));
1001 static int ll_rmdir(struct inode *dir, struct dentry *dentry)
1003 struct inode * inode = dentry->d_inode;
1004 struct lookup_intent *it;
1008 LL_GET_INTENT(dentry, it);
1010 if ((!it || !it->it_disposition) && !ext2_empty_dir(inode))
1013 rc = ll_common_unlink(dir, dentry, it, S_IFDIR);
1016 ext2_dec_count(inode);
1017 ext2_dec_count(dir);
1023 static int ll_rename2(struct inode *src, struct inode *tgt,
1024 const char *oldname, int oldlen,
1025 const char *newname, int newlen)
1027 struct ptlrpc_request *request = NULL;
1028 struct ll_sb_info *sbi = ll_i2sbi(src);
1032 err = mdc_rename(&sbi->ll_mdc_conn, src, tgt,
1033 oldname, oldlen, newname, newlen, &request);
1034 ptlrpc_req_finished(request);
1041 static int ll_rename(struct inode * old_dir, struct dentry * old_dentry,
1042 struct inode * new_dir, struct dentry * new_dentry)
1044 struct lookup_intent *it;
1045 struct inode * old_inode = old_dentry->d_inode;
1046 struct inode * tgt_inode = new_dentry->d_inode;
1047 struct page * dir_page = NULL;
1048 struct ext2_dir_entry_2 * dir_de = NULL;
1049 struct ext2_dir_entry_2 * old_de;
1050 struct page * old_page;
1053 LL_GET_INTENT(new_dentry, it);
1055 if (it && it->it_disposition) {
1057 tgt_inode->i_ctime = CURRENT_TIME;
1058 tgt_inode->i_nlink--;
1060 ll_invalidate_inode_pages(old_dir);
1061 ll_invalidate_inode_pages(new_dir);
1062 GOTO(out, err = it->it_status);
1065 err = ll_rename2(old_dir, new_dir,
1066 old_dentry->d_name.name, old_dentry->d_name.len,
1067 new_dentry->d_name.name, new_dentry->d_name.len);
1071 old_de = ext2_find_entry (old_dir, old_dentry, &old_page);
1075 if (S_ISDIR(old_inode->i_mode)) {
1077 dir_de = ext2_dotdot(old_inode, &dir_page);
1083 struct page *new_page;
1084 struct ext2_dir_entry_2 *new_de;
1087 if (dir_de && !ext2_empty_dir (tgt_inode))
1091 new_de = ext2_find_entry (new_dir, new_dentry, &new_page);
1094 ext2_inc_count(old_inode);
1095 ext2_set_link(new_dir, new_de, new_page, old_inode);
1096 tgt_inode->i_ctime = CURRENT_TIME;
1098 tgt_inode->i_nlink--;
1099 ext2_dec_count(tgt_inode);
1103 if (new_dir->i_nlink >= EXT2_LINK_MAX)
1106 ext2_inc_count(old_inode);
1107 err = ll_add_link(new_dentry, old_inode);
1109 ext2_dec_count(old_inode);
1113 ext2_inc_count(new_dir);
1116 ext2_delete_entry (old_de, old_page);
1117 ext2_dec_count(old_inode);
1120 ext2_set_link(old_inode, dir_de, dir_page, new_dir);
1121 ext2_dec_count(old_dir);
1128 page_cache_release(dir_page);
1132 page_cache_release(old_page);
1137 extern int ll_inode_revalidate(struct dentry *dentry);
1138 struct inode_operations ll_dir_inode_operations = {
1140 lookup2: ll_lookup2,
1144 unlink2: ll_unlink2,
1145 symlink: ll_symlink,
1146 symlink2: ll_symlink2,
1154 rename2: ll_rename2,
1155 setattr: ll_setattr,
1156 revalidate: ll_inode_revalidate,