Whamcloud - gitweb
- Rename the ptlrpc-general reconnection and replay functions, and export them
[fs/lustre-release.git] / lustre / llite / namei.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * This code is issued under the GNU General Public License.
5  * See the file COPYING in this distribution
6  *
7  * Copyright (C) 1992, 1993, 1994, 1995
8  * Remy Card (card@masi.ibp.fr)
9  * Laboratoire MASI - Institut Blaise Pascal
10  * Universite Pierre et Marie Curie (Paris VI)
11  *
12  *  from
13  *
14  *  linux/fs/ext2/namei.c
15  *
16  *  Copyright (C) 1991, 1992  Linus Torvalds
17  *
18  *  Big-endian to little-endian byte-swapping/bitmaps by
19  *        David S. Miller (davem@caip.rutgers.edu), 1995
20  *  Directory entry file type support and forward compatibility hooks
21  *      for B-tree directories by Theodore Ts'o (tytso@mit.edu), 1998
22  *
23  *  Changes for use in OBDFS
24  *  Copyright (c) 1999, Seagate Technology Inc.
25  *  Copyright (C) 2001, Cluster File Systems, Inc.
26  *                       Rewritten based on recent ext2 page cache use.
27  *
28  */
29
30 #include <linux/fs.h>
31 #include <linux/locks.h>
32 #include <linux/quotaops.h>
33
34 #define DEBUG_SUBSYSTEM S_LLITE
35
36 #include <linux/obd_support.h>
37 #include <linux/lustre_lite.h>
38 #include <linux/lustre_dlm.h>
39 #include <linux/obd_lov.h>
40
41 extern struct address_space_operations ll_aops;
42
43 /* from super.c */
44 extern void ll_change_inode(struct inode *inode);
45 extern int ll_setattr(struct dentry *de, struct iattr *attr);
46
47 /* from dir.c */
48 extern int ll_add_link (struct dentry *dentry, struct inode *inode);
49 obd_id ll_inode_by_name(struct inode * dir, struct dentry *dentry, int *typ);
50 int ext2_make_empty(struct inode *inode, struct inode *parent);
51 struct ext2_dir_entry_2 * ext2_find_entry (struct inode * dir,
52                    struct dentry *dentry, struct page ** res_page);
53 int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page );
54 int ext2_empty_dir (struct inode * inode);
55 struct ext2_dir_entry_2 * ext2_dotdot (struct inode *dir, struct page **p);
56 void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
57                    struct page *page, struct inode *inode);
58
59 /*
60  * Couple of helper functions - make the code slightly cleaner.
61  */
62 static inline void ext2_inc_count(struct inode *inode)
63 {
64         inode->i_nlink++;
65 }
66
67 /* postpone the disk update until the inode really goes away */
68 static inline void ext2_dec_count(struct inode *inode)
69 {
70         inode->i_nlink--;
71 }
72
73 static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
74 {
75         int err;
76         err = ll_add_link(dentry, inode);
77         if (!err) {
78                 d_instantiate(dentry, inode);
79                 return 0;
80         }
81         ext2_dec_count(inode);
82         iput(inode);
83         return err;
84 }
85
86 /* methods */
87 static int ll_find_inode(struct inode *inode, unsigned long ino, void *opaque)
88 {
89         struct ll_read_inode2_cookie *lic = opaque;
90         struct mds_body *body = lic->lic_body;
91
92         if (inode->i_generation != lic->lic_body->generation)
93                 return 0;
94
95         /* Apply the attributes in 'opaque' to this inode */
96         ll_update_inode(inode, body);
97
98         return 1;
99 }
100
101 extern struct dentry_operations ll_d_ops;
102
103 int ll_lock(struct inode *dir, struct dentry *dentry,
104             struct lookup_intent *it, struct lustre_handle *lockh)
105 {
106         struct ll_sb_info *sbi = ll_i2sbi(dir);
107         char *tgt = NULL;
108         int tgtlen = 0;
109         int err, lock_mode;
110
111         if ((it->it_op & (IT_CREAT | IT_MKDIR | IT_SETATTR | IT_MKNOD)))
112                 lock_mode = LCK_PW;
113         else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_UNLINK |
114                               IT_RMDIR | IT_RENAME | IT_RENAME2 | IT_READLINK|
115                               IT_LINK | IT_LINK2))
116                 lock_mode = LCK_PR;
117         else if (it->it_op & IT_SYMLINK) {
118                 lock_mode = LCK_PW;
119                 tgt = it->it_data;
120                 tgtlen = strlen(tgt);
121                 it->it_data = NULL;
122         } else if (it->it_op & IT_LOOKUP)
123                 lock_mode = LCK_PR;
124         else {
125                 LBUG();
126                 RETURN(-EINVAL);
127         }
128
129         err = mdc_enqueue(&sbi->ll_mdc_conn, LDLM_MDSINTENT, it, lock_mode,
130                           dir, dentry, lockh, tgt, tgtlen, dir, sizeof(*dir));
131
132         RETURN(err);
133 }
134
135 int ll_unlock(__u32 mode, struct lustre_handle *lockh)
136 {
137         ENTRY;
138
139         ldlm_lock_decref(lockh, mode);
140
141         RETURN(0);
142 }
143
144 static struct dentry *ll_lookup2(struct inode *dir, struct dentry *dentry,
145                                  struct lookup_intent *it)
146 {
147         struct ptlrpc_request *request = NULL;
148         struct inode * inode = NULL;
149         struct ll_sb_info *sbi = ll_i2sbi(dir);
150         struct ll_read_inode2_cookie lic;
151         struct lustre_handle lockh;
152         struct lookup_intent lookup_it = { IT_LOOKUP };
153         int err, offset;
154         obd_id ino = 0;
155
156         ENTRY;
157
158         /* CHECK_MOUNT_EPOCH(dir); */
159         if (ll_i2info(dir)->lli_mount_epoch != ll_i2sbi(dir)->ll_mount_epoch)
160                 RETURN(ERR_PTR(-EIO));
161
162         if (it == NULL) {
163                 it = &lookup_it;
164                 dentry->d_it = it;
165         }
166
167         CDEBUG(D_INFO, "name: %*s, intent: %s\n", dentry->d_name.len,
168                dentry->d_name.name, ldlm_it2str(it->it_op));
169
170         if (dentry->d_name.len > EXT2_NAME_LEN)
171                 RETURN(ERR_PTR(-ENAMETOOLONG));
172
173         err = ll_lock(dir, dentry, it, &lockh);
174         if (err < 0)
175                 RETURN(ERR_PTR(err));
176         memcpy(it->it_lock_handle, &lockh, sizeof(lockh));
177
178         request = (struct ptlrpc_request *)it->it_data;
179         if (it->it_disposition) {
180                 int mode, symlen = 0;
181                 obd_flag valid;
182
183                 offset = 1;
184                 lic.lic_body = lustre_msg_buf(request->rq_repmsg, offset);
185                 ino = lic.lic_body->fid1.id;
186                 mode = lic.lic_body->mode;
187                 if (it->it_op & (IT_CREAT | IT_MKDIR | IT_SYMLINK | IT_MKNOD)) {
188                         /* For create ops, we want the lookup to be negative,
189                          * unless the create failed in a way that indicates
190                          * that the file is already there */
191                         if (it->it_status != -EEXIST)
192                                 GOTO(negative, NULL);
193                 } else if (it->it_op & (IT_GETATTR | IT_SETATTR | IT_LOOKUP)) {
194                         /* For check ops, we want the lookup to succeed */
195                         it->it_data = NULL;
196                         if (it->it_status)
197                                 GOTO(neg_req, NULL);
198                 } else if (it->it_op & (IT_RENAME | IT_LINK)) {
199                         /* For rename, we want the lookup to succeed */
200                         if (it->it_status) {
201                                 it->it_data = NULL;
202                                 GOTO(neg_req, NULL);
203                         }
204                         it->it_data = dentry;
205                 } else if (it->it_op & (IT_UNLINK | IT_RMDIR)) {
206                         /* For remove ops, we want the lookup to succeed unless
207                          * the file truly doesn't exist */
208                         it->it_data = NULL;
209                         if (it->it_status == -ENOENT)
210                                 GOTO(neg_req, NULL);
211                         goto iget;
212                 } else if (it->it_op == IT_OPEN) {
213                         it->it_data = NULL;
214                         if (it->it_status && it->it_status != -EEXIST)
215                                 GOTO(neg_req, NULL);
216                 } else if (it->it_op & (IT_RENAME2|IT_LINK2)) {
217                         struct mds_body *body =
218                                 lustre_msg_buf(request->rq_repmsg, offset);
219                         it->it_data = NULL;
220                         /* For rename2, this means the lookup is negative */
221                         /* For link2 also */
222                         if (body->valid == 0)
223                                 GOTO(neg_req, NULL);
224                         goto iget;
225                 }
226
227                 /* Do a getattr now that we have the lock */
228                 valid = OBD_MD_FLNOTOBD | OBD_MD_FLEASIZE;
229                 if (it->it_op == IT_READLINK) {
230                         valid |= OBD_MD_LINKNAME;
231                         symlen = lic.lic_body->size;
232                 }
233                 ptlrpc_req_finished(request);
234                 request = NULL;
235                 err = mdc_getattr(&sbi->ll_mdc_conn, ino, mode,
236                                   valid, symlen, &request);
237                 if (err) {
238                         CERROR("failure %d inode %Ld\n", err, (long long)ino);
239                         GOTO(drop_req, err = -abs(err));
240                 }
241                 offset = 0;
242         } else {
243                 struct ll_inode_info *lli = ll_i2info(dir);
244                 int mode;
245
246                 memcpy(&lli->lli_intent_lock_handle, &lockh, sizeof(lockh));
247                 offset = 0;
248
249                 ino = ll_inode_by_name(dir, dentry, &mode);
250                 if (!ino) {
251                         CERROR("inode %*s not found by name\n",
252                                dentry->d_name.len, dentry->d_name.name);
253                         GOTO(drop_lock, err = -ENOENT);
254                 }
255
256                 err = mdc_getattr(&sbi->ll_mdc_conn, ino, mode,
257                                   OBD_MD_FLNOTOBD|OBD_MD_FLEASIZE, 0, &request);
258                 if (err) {
259                         CERROR("failure %d inode %Ld\n", err, (long long)ino);
260                         GOTO(drop_req, err = -abs(err));
261                 }
262         }
263
264  iget:
265         lic.lic_body = lustre_msg_buf(request->rq_repmsg, offset);
266         if (S_ISREG(lic.lic_body->mode) &&
267             lic.lic_body->valid & OBD_MD_FLEASIZE) {
268                 LASSERT(request->rq_repmsg->bufcount > offset);
269                 lic.lic_lmm = lustre_msg_buf(request->rq_repmsg, offset + 1);
270         } else
271                 lic.lic_lmm = NULL;
272
273         /* No rpc's happen during iget4, -ENOMEM's are possible */
274         LASSERT(ino != 0);
275         inode = iget4(dir->i_sb, ino, ll_find_inode, &lic);
276
277         if (!inode) {
278                 ptlrpc_free_req(request);
279                 ll_intent_release(dentry);
280                 RETURN(ERR_PTR(-ENOMEM));
281         }
282
283         EXIT;
284  neg_req:
285         ptlrpc_req_finished(request);
286  negative:
287         dentry->d_op = &ll_d_ops;
288         d_add(dentry, inode);
289
290         if (ll_d2d(dentry) == NULL)
291                 ll_set_dd(dentry);
292         // down(&ll_d2d(dentry)->lld_it_sem);
293         // dentry->d_it = it;        
294
295         if (it->it_op == IT_LOOKUP)
296                 ll_intent_release(dentry);
297
298         return NULL;
299
300  drop_req:
301         ptlrpc_free_req(request);
302  drop_lock:
303 #warning FIXME: must release lock here
304         return ERR_PTR(err);
305 }
306
307 static struct inode *ll_create_node(struct inode *dir, const char *name,
308                                     int namelen, const char *tgt, int tgtlen,
309                                     int mode, __u64 extra,
310                                     struct lookup_intent *it,
311                                     struct lov_stripe_md *lsm)
312 {
313         struct inode *inode;
314         struct ptlrpc_request *request = NULL;
315         struct mds_body *body;
316         int rc;
317         time_t time = CURRENT_TIME;
318         struct ll_sb_info *sbi = ll_i2sbi(dir);
319         int gid = current->fsgid;
320         struct ll_read_inode2_cookie lic;
321         struct lov_mds_md *lmm = NULL;
322         int mds_md_size = 0;
323
324         ENTRY;
325
326         if (dir->i_mode & S_ISGID) {
327                 gid = dir->i_gid;
328                 if (S_ISDIR(mode))
329                         mode |= S_ISGID;
330         }
331
332         if (!it || !it->it_disposition) {
333                 rc = mdc_create(&sbi->ll_mdc_conn, dir, name, namelen, tgt,
334                                  tgtlen, mode, current->fsuid,
335                                  gid, time, extra, lsm, &request);
336                 if (rc) {
337                         inode = ERR_PTR(rc);
338                         GOTO(out, rc);
339                 }
340                 body = lustre_msg_buf(request->rq_repmsg, 0);
341                 if (lsm != NULL) {
342                         mds_md_size = ll_mds_easize(dir->i_sb);
343                         OBD_ALLOC(lmm, mds_md_size);
344                         lov_packmd(lmm, lsm);
345                         lic.lic_lmm = lmm;
346                 } else
347                         lic.lic_lmm = NULL;
348
349         } else {
350                 invalidate_inode_pages(dir);
351                 request = it->it_data;
352                 body = lustre_msg_buf(request->rq_repmsg, 1);
353                 lic.lic_lmm = NULL;
354         }
355
356         body->valid = OBD_MD_FLNOTOBD;
357
358         body->nlink = 1;
359         body->atime = body->ctime = body->mtime = time;
360         body->uid = current->fsuid;
361         body->gid = gid;
362         body->mode = mode;
363
364         lic.lic_body = body;
365
366         inode = iget4(dir->i_sb, body->ino, ll_find_inode, &lic);
367         if (IS_ERR(inode)) {
368                 rc = PTR_ERR(inode);
369                 CERROR("new_inode -fatal: rc %d\n", rc);
370                 LBUG();
371                 GOTO(out, rc);
372         }
373
374         if (!list_empty(&inode->i_dentry)) {
375                 CERROR("new_inode -fatal: inode %d, ct %d lnk %d\n",
376                        body->ino, atomic_read(&inode->i_count),
377                        inode->i_nlink);
378                 iput(inode);
379                 LBUG();
380                 inode = ERR_PTR(-EIO);
381                 GOTO(out, -EIO);
382         }
383
384         EXIT;
385  out:
386         if (lmm)
387                 OBD_FREE(lmm, mds_md_size);
388         ptlrpc_req_finished(request);
389         return inode;
390 }
391
392 static int ll_mdc_unlink(struct inode *dir, struct inode *child, __u32 mode,
393                          const char *name, int len)
394 {
395         struct ptlrpc_request *request = NULL;
396         struct ll_sb_info *sbi = ll_i2sbi(dir);
397         int err;
398
399         ENTRY;
400
401         err = mdc_unlink(&sbi->ll_mdc_conn, dir, child, mode, name, len,
402                          &request);
403         ptlrpc_req_finished(request);
404
405         RETURN(err);
406 }
407
408 int ll_mdc_link(struct dentry *src, struct inode *dir,
409                 const char *name, int len)
410 {
411         struct ptlrpc_request *request = NULL;
412         int err;
413         struct ll_sb_info *sbi = ll_i2sbi(dir);
414
415         ENTRY;
416
417         err = mdc_link(&sbi->ll_mdc_conn, src, dir, name,
418                        len, &request);
419         ptlrpc_req_finished(request);
420
421         RETURN(err);
422 }
423
424 int ll_mdc_rename(struct inode *src, struct inode *tgt,
425                   struct dentry *old, struct dentry *new)
426 {
427         struct ptlrpc_request *request = NULL;
428         struct ll_sb_info *sbi = ll_i2sbi(src);
429         int err;
430
431         ENTRY;
432
433         err = mdc_rename(&sbi->ll_mdc_conn, src, tgt,
434                          old->d_name.name, old->d_name.len,
435                          new->d_name.name, new->d_name.len, &request);
436         ptlrpc_req_finished(request);
437
438         RETURN(err);
439 }
440
441 /*
442  * By the time this is called, we already have created
443  * the directory cache entry for the new file, but it
444  * is so far negative - it has no inode.
445  *
446  * If the create succeeds, we fill in the inode information
447  * with d_instantiate().
448  */
449
450 static int ll_create(struct inode * dir, struct dentry * dentry, int mode)
451 {
452         int err, rc = 0;
453         struct obdo *oa = NULL;
454         struct inode *inode;
455         struct lov_stripe_md *lsm = NULL;
456         struct ll_inode_info *lli = NULL;
457         ENTRY;
458
459         CHECK_MOUNT_EPOCH(dir);
460
461         if (dentry->d_it->it_disposition == 0) {
462                 int gid = current->fsgid;
463
464                 if (dir->i_mode & S_ISGID)
465                         gid = dir->i_gid;
466
467                 oa = obdo_alloc();
468                 if (!oa)
469                         RETURN(-ENOMEM);
470
471                 oa->o_mode = S_IFREG | 0600;
472                 /* FIXME: we set the UID/GID fields to 0 for now, because it
473                  *        fixes a bug on the BA OSTs.  We should really set
474                  *        them properly, and this needs to be revisited when
475                  *        we do proper credentials checking on the OST, and
476                  *        set the attributes on the OST in ll_inode_setattr().
477                 oa->o_uid = current->fsuid;
478                 oa->o_gid = gid;
479                  */
480                 oa->o_uid = 0;
481                 oa->o_gid = 0;
482                 oa->o_valid = OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLUID |
483                         OBD_MD_FLGID;
484                 rc = obd_create(ll_i2obdconn(dir), oa, &lsm);
485                 CDEBUG(D_DENTRY, "name %s mode %o o_id "LPX64": rc = %d\n",
486                        dentry->d_name.name, mode, oa->o_id, rc);
487                 if (rc)
488                         GOTO(out_free, rc);
489         }
490
491         inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
492                                NULL, 0, mode, 0, dentry->d_it, lsm);
493
494         if (IS_ERR(inode)) {
495                 rc = PTR_ERR(inode);
496                 CERROR("error creating MDS object for id "LPX64": rc = %d\n",
497                        oa->o_id, rc);
498                 GOTO(out_destroy, rc);
499         }
500
501         if (dentry->d_it->it_disposition) {
502                 lli = ll_i2info(inode);
503                 memcpy(&lli->lli_intent_lock_handle,
504                        dentry->d_it->it_lock_handle,
505                        sizeof(struct lustre_handle));
506                 d_instantiate(dentry, inode);
507         } else {
508                 /* no directory data updates when intents rule */
509                 rc = ext2_add_nondir(dentry, inode);
510         }
511
512 out_free:
513         obdo_free(oa);
514         RETURN(rc);
515
516 out_destroy:
517         if (lsm) {
518                 if (!oa)
519                         oa = obdo_alloc();
520                 if (!oa)
521                         RETURN(-ENOMEM);
522
523                 oa->o_easize = ll_mds_easize(inode->i_sb);
524                 oa->o_valid |= OBD_MD_FLEASIZE;
525                 err = obd_destroy(ll_i2obdconn(dir), oa, lsm);
526                 if (err)
527                         CERROR("error uncreating objid "LPX64": err %d\n",
528                                oa->o_id, err);
529         }
530
531         goto out_free;
532 }
533
534 static int ll_mknod(struct inode *dir, struct dentry *dentry, int mode,
535                     int rdev)
536 {
537         struct inode *inode;
538         int err = 0;
539
540         inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
541                                NULL, 0, mode, rdev, dentry->d_it, NULL);
542
543         if (IS_ERR(inode))
544                 RETURN(PTR_ERR(inode));
545
546         /* no directory data updates when intents rule */
547         if (dentry->d_it && dentry->d_it->it_disposition)
548                 d_instantiate(dentry, inode);
549         else
550                 err = ext2_add_nondir(dentry, inode);
551
552         return err;
553 }
554
555 static int ll_symlink(struct inode *dir, struct dentry *dentry,
556                       const char *symname)
557 {
558         unsigned l = strlen(symname);
559         struct inode *inode;
560         struct ll_inode_info *lli;
561         int err = 0;
562         ENTRY;
563
564         CHECK_MOUNT_EPOCH(dir);
565
566         inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
567                                symname, l, S_IFLNK | S_IRWXUGO, 0,
568                                dentry->d_it, NULL);
569         if (IS_ERR(inode))
570                 RETURN(PTR_ERR(inode));
571
572         lli = ll_i2info(inode);
573
574         OBD_ALLOC(lli->lli_symlink_name, l + 1);
575         /* this _could_ be a non-fatal error, since the symlink is already
576          * stored on the MDS by this point, and we can re-get it in readlink.
577          */
578         if (!lli->lli_symlink_name)
579                 RETURN(-ENOMEM);
580
581         memcpy(lli->lli_symlink_name, symname, l + 1);
582         inode->i_size = l;
583
584         /* no directory data updates when intents rule */
585         if (dentry->d_it && dentry->d_it->it_disposition)
586                 d_instantiate(dentry, inode);
587         else
588                 err = ext2_add_nondir(dentry, inode);
589
590         RETURN(err);
591 }
592
593 static int ll_link(struct dentry *old_dentry, struct inode * dir,
594                    struct dentry *dentry)
595 {
596         int err;
597         struct inode *inode = old_dentry->d_inode;
598
599         if (dentry->d_it && dentry->d_it->it_disposition) { 
600                 int err = dentry->d_it->it_status;
601                 if (err) 
602                         RETURN(err);
603                 inode->i_ctime = CURRENT_TIME;
604                 ext2_inc_count(inode);
605                 atomic_inc(&inode->i_count);
606                 d_instantiate(dentry, inode);
607                 invalidate_inode_pages(dir);
608                 RETURN(err);
609         }
610
611         if (S_ISDIR(inode->i_mode))
612                 return -EPERM;
613
614         if (inode->i_nlink >= EXT2_LINK_MAX)
615                 return -EMLINK;
616
617         err = ll_mdc_link(old_dentry, dir,
618                           dentry->d_name.name, dentry->d_name.len);
619         if (err)
620                 RETURN(err);
621
622         inode->i_ctime = CURRENT_TIME;
623         ext2_inc_count(inode);
624         atomic_inc(&inode->i_count);
625
626         return ext2_add_nondir(dentry, inode);
627 }
628
629 static int ll_mkdir(struct inode * dir, struct dentry * dentry, int mode)
630 {
631         struct inode * inode;
632         int err = -EMLINK;
633         ENTRY;
634
635         if (dir->i_nlink >= EXT2_LINK_MAX)
636                 goto out;
637
638         ext2_inc_count(dir);
639
640         inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
641                                NULL, 0, S_IFDIR | mode, 0, dentry->d_it, NULL);
642         err = PTR_ERR(inode);
643         if (IS_ERR(inode))
644                 goto out_dir;
645
646         ext2_inc_count(inode);
647
648         err = ext2_make_empty(inode, dir);
649         if (err)
650                 goto out_fail;
651
652         /* no directory data updates when intents rule */
653         if (dentry->d_it->it_disposition == 0) {
654                 err = ll_add_link(dentry, inode);
655                 if (err)
656                         goto out_fail;
657         }
658
659         d_instantiate(dentry, inode);
660 out:
661         EXIT;
662         return err;
663
664 out_fail:
665         ext2_dec_count(inode);
666         ext2_dec_count(inode);
667         iput(inode);
668         EXIT;
669 out_dir:
670         ext2_dec_count(dir);
671         EXIT;
672         goto out;
673 }
674
675 static int ll_common_unlink(struct inode *dir, struct dentry *dentry,
676                             __u32 mode)
677 {
678         struct inode * inode = dentry->d_inode;
679 #if 0
680         struct ext2_dir_entry_2 * de;
681         struct page * page;
682 #endif
683         int err = -ENOENT;
684
685         if (dentry->d_it && dentry->d_it->it_disposition) {
686                 err = dentry->d_it->it_status;
687                 invalidate_inode_pages(dir);
688                 GOTO(out, err);
689         }
690
691 #if 0
692         de = ext2_find_entry(dir, dentry, &page);
693         if (!de)
694                 goto out;
695 #endif
696         err = ll_mdc_unlink(dir, dentry->d_inode, mode,
697                             dentry->d_name.name, dentry->d_name.len);
698         if (err)
699                 goto out;
700
701 #if 0
702         err = ext2_delete_entry(de, page);
703         if (err)
704                 goto out;
705 #endif
706         invalidate_inode_pages(dir);
707
708         inode->i_ctime = dir->i_ctime;
709 out:
710         ext2_dec_count(inode);
711         return err;
712 }
713
714 static int ll_unlink(struct inode *dir, struct dentry *dentry)
715 {
716         return ll_common_unlink(dir, dentry, S_IFREG);
717 }
718
719 static int ll_rmdir(struct inode *dir, struct dentry *dentry)
720 {
721         struct inode * inode = dentry->d_inode;
722         int err = 0;
723         ENTRY;
724
725         if (!dentry->d_it || dentry->d_it->it_disposition == 0) {
726                 if (!ext2_empty_dir(inode))
727                         RETURN(-ENOTEMPTY);
728                 err = ll_common_unlink(dir, dentry, S_IFDIR);
729         } else
730                 err = dentry->d_it->it_status;
731         if (err)
732                 RETURN(err);
733         inode->i_size = 0;
734         ext2_dec_count(inode);
735         ext2_dec_count(dir);
736         RETURN(err);
737 }
738
739 static int ll_rename(struct inode * old_dir, struct dentry * old_dentry,
740                      struct inode * new_dir, struct dentry * new_dentry)
741 {
742         struct inode * old_inode = old_dentry->d_inode;
743         struct inode * tgt_inode = new_dentry->d_inode;
744         struct page * dir_page = NULL;
745         struct ext2_dir_entry_2 * dir_de = NULL;
746         struct ext2_dir_entry_2 * old_de;
747         struct page * old_page;
748         int err = -ENOENT;
749
750         if (new_dentry->d_it && new_dentry->d_it->it_disposition) { 
751                 if (tgt_inode) {
752                         tgt_inode->i_ctime = CURRENT_TIME;
753                         tgt_inode->i_nlink--;
754                 }
755                 invalidate_inode_pages(old_dir);
756                 invalidate_inode_pages(new_dir);
757                 GOTO(out, err = new_dentry->d_it->it_status);
758         }
759
760         err = ll_mdc_rename(old_dir, new_dir, old_dentry, new_dentry);
761         if (err)
762                 goto out;
763
764         old_de = ext2_find_entry (old_dir, old_dentry, &old_page);
765         if (!old_de)
766                 goto out;
767
768         if (S_ISDIR(old_inode->i_mode)) {
769                 err = -EIO;
770                 dir_de = ext2_dotdot(old_inode, &dir_page);
771                 if (!dir_de)
772                         goto out_old;
773         }
774
775         if (tgt_inode) {
776                 struct page *new_page;
777                 struct ext2_dir_entry_2 *new_de;
778
779                 err = -ENOTEMPTY;
780                 if (dir_de && !ext2_empty_dir (tgt_inode))
781                         goto out_dir;
782
783                 err = -ENOENT;
784                 new_de = ext2_find_entry (new_dir, new_dentry, &new_page);
785                 if (!new_de)
786                         goto out_dir;
787                 ext2_inc_count(old_inode);
788                 ext2_set_link(new_dir, new_de, new_page, old_inode);
789                 tgt_inode->i_ctime = CURRENT_TIME;
790                 if (dir_de)
791                         tgt_inode->i_nlink--;
792                 ext2_dec_count(tgt_inode);
793         } else {
794                 if (dir_de) {
795                         err = -EMLINK;
796                         if (new_dir->i_nlink >= EXT2_LINK_MAX)
797                                 goto out_dir;
798                 }
799                 ext2_inc_count(old_inode);
800                 err = ll_add_link(new_dentry, old_inode);
801                 if (err) {
802                         ext2_dec_count(old_inode);
803                         goto out_dir;
804                 }
805                 if (dir_de)
806                         ext2_inc_count(new_dir);
807         }
808
809         ext2_delete_entry (old_de, old_page);
810         ext2_dec_count(old_inode);
811
812         if (dir_de) {
813                 ext2_set_link(old_inode, dir_de, dir_page, new_dir);
814                 ext2_dec_count(old_dir);
815         }
816         return 0;
817
818 out_dir:
819         if (dir_de) {
820                 kunmap(dir_page);
821                 page_cache_release(dir_page);
822         }
823 out_old:
824         kunmap(old_page);
825         page_cache_release(old_page);
826 out:
827         return err;
828 }
829
830 struct inode_operations ll_dir_inode_operations = {
831         create:         ll_create,
832         lookup2:        ll_lookup2,
833         link:           ll_link,
834         unlink:         ll_unlink,
835         symlink:        ll_symlink,
836         mkdir:          ll_mkdir,
837         rmdir:          ll_rmdir,
838         mknod:          ll_mknod,
839         rename:         ll_rename,
840         setattr:        ll_setattr
841 };