]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] iget_locked [3/6]
authorJan Harkes <jaharkes@cs.cmu.edu>
Mon, 20 May 2002 02:25:07 +0000 (19:25 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Mon, 20 May 2002 02:25:07 +0000 (19:25 -0700)
Convert existing filesystems (Coda/NFS/ReiserFS) that currently use
iget4 to iget5_locked.

fs/coda/cnode.c
fs/coda/inode.c
fs/nfs/inode.c
fs/reiserfs/inode.c
fs/reiserfs/super.c
include/linux/fs.h
include/linux/nfs_fs.h
include/linux/reiserfs_fs.h

index a75444e66eef5fa53adccee348f2a93229fe86e9..f541d14c47f1406ea200af3ff795675fc801d90c 100644 (file)
@@ -72,13 +72,21 @@ struct inode * coda_iget(struct super_block * sb, ViceFid * fid,
                         struct coda_vattr * attr)
 {
        struct inode *inode;
+       struct coda_inode_info *cii;
+       struct coda_sb_info *sbi = coda_sbp(sb);
        ino_t ino = coda_f2i(fid);
 
-       inode = iget4(sb, ino, coda_test_inode, coda_set_inode, fid);
+       inode = iget5_locked(sb, ino, coda_test_inode, coda_set_inode, fid);
 
        if (!inode)
                return ERR_PTR(-ENOMEM);
 
+       if (inode->i_state & I_NEW) {
+               cii = ITOC(inode);
+               list_add(&cii->c_cilist, &sbi->sbi_cihead);
+               unlock_new_inode(inode);
+       }
+
        /* always replace the attributes, type might have changed */
        coda_fill_inode(inode, attr);
        return inode;
@@ -141,12 +149,13 @@ struct inode *coda_fid_to_inode(ViceFid *fid, struct super_block *sb)
        }
 
        nr = coda_f2i(fid);
-       inode = iget4(sb, nr, coda_test_inode, coda_fail_inode, fid);
-       if ( !inode ) {
-               printk("coda_fid_to_inode: null from iget, sb %p, nr %ld.\n",
-                      sb, (long)nr);
+       inode = iget5_locked(sb, nr, coda_test_inode, coda_fail_inode, fid);
+       if ( !inode )
                return NULL;
-       }
+
+       /* we should never see newly created inodes because we intentionally
+        * fail in the initialization callback */
+       BUG_ON(inode->i_state & I_NEW);
 
        return inode;
 }
@@ -156,8 +165,9 @@ int coda_cnode_makectl(struct inode **inode, struct super_block *sb)
 {
        int error = -ENOMEM;
 
-       *inode = iget(sb, CTL_INO);
-       if ( *inode ) {
+       *inode = new_inode(sb);
+       if (*inode) {
+               (*inode)->i_ino = CTL_INO;
                (*inode)->i_op = &coda_ioctl_inode_operations;
                (*inode)->i_fop = &coda_ioctl_operations;
                (*inode)->i_mode = 0444;
index 8a68f2a13461cb8bbd687b75b4b47f68d4c0ed5d..621074e23410ae841a40f4347b738e2ab9ae43d7 100644 (file)
@@ -33,7 +33,6 @@
 #include <linux/coda_cache.h>
 
 /* VFS super_block ops */
-static void coda_read_inode(struct inode *);
 static void coda_clear_inode(struct inode *);
 static void coda_put_super(struct super_block *);
 static int coda_statfs(struct super_block *sb, struct statfs *buf);
@@ -92,7 +91,6 @@ struct super_operations coda_super_operations =
 {
        alloc_inode:    coda_alloc_inode,
        destroy_inode:  coda_destroy_inode,
-       read_inode:     coda_read_inode,
        clear_inode:    coda_clear_inode,
        put_super:      coda_put_super,
        statfs:         coda_statfs,
@@ -229,18 +227,6 @@ static void coda_put_super(struct super_block *sb)
        kfree(sbi);
 }
 
-/* all filling in of inodes postponed until lookup */
-static void coda_read_inode(struct inode *inode)
-{
-       struct coda_sb_info *sbi = coda_sbp(inode->i_sb);
-       struct coda_inode_info *cii;
-
-        if (!sbi) BUG();
-
-       cii = ITOC(inode);
-       list_add(&cii->c_cilist, &sbi->sbi_cihead);
-}
-
 static void coda_clear_inode(struct inode *inode)
 {
        struct coda_inode_info *cii = ITOC(inode);
index 030c570e30f52a0b13e65c4126a8b79684d2d3fd..63710b5552ec884fbf2fce868f45c4dcc4cd637c 100644 (file)
@@ -47,7 +47,6 @@ static void nfs_invalidate_inode(struct inode *);
 
 static struct inode *nfs_alloc_inode(struct super_block *sb);
 static void nfs_destroy_inode(struct inode *);
-static void nfs_read_inode(struct inode *);
 static void nfs_write_inode(struct inode *,int);
 static void nfs_delete_inode(struct inode *);
 static void nfs_put_super(struct super_block *);
@@ -59,7 +58,6 @@ static int  nfs_show_options(struct seq_file *, struct vfsmount *);
 static struct super_operations nfs_sops = { 
        alloc_inode:    nfs_alloc_inode,
        destroy_inode:  nfs_destroy_inode,
-       read_inode:     nfs_read_inode,
        write_inode:    nfs_write_inode,
        delete_inode:   nfs_delete_inode,
        put_super:      nfs_put_super,
@@ -98,15 +96,6 @@ nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
        return nfs_fileid_to_ino_t(fattr->fileid);
 }
 
-/*
- * The "read_inode" function doesn't actually do anything:
- * the real data is filled in later in nfs_fhget.
- */
-static void
-nfs_read_inode(struct inode * inode)
-{
-}
-
 static void
 nfs_write_inode(struct inode *inode, int sync)
 {
@@ -664,16 +653,15 @@ __nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
 
        ino = nfs_fattr_to_ino_t(fattr);
 
-       if (!(inode = iget4(sb, ino, nfs_find_actor, nfs_init_locked, &desc)))
+       if (!(inode = iget5_locked(sb, ino, nfs_find_actor, nfs_init_locked, &desc)))
                goto out_no_inode;
 
-       if (NFS_NEW(inode)) {
+       if (inode->i_state & I_NEW) {
                __u64           new_size, new_mtime;
                loff_t          new_isize;
                time_t          new_atime;
 
                /* We can't support UPDATE_ATIME(), since the server will reset it */
-               NFS_FLAGS(inode) &= ~NFS_INO_NEW;
                inode->i_flags |= S_NOATIME;
                inode->i_mode = fattr->mode;
                /* Why so? Because we want revalidate for devices/FIFOs, and
@@ -721,6 +709,8 @@ __nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                NFS_ATTRTIMEO(inode) = NFS_MINATTRTIMEO(inode);
                NFS_ATTRTIMEO_UPDATE(inode) = jiffies;
                memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
+
+               unlock_new_inode(inode);
        } else
                nfs_refresh_inode(inode, fattr);
        dprintk("NFS: __nfs_fhget(%s/%Ld ct=%d)\n",
@@ -1241,7 +1231,7 @@ static struct inode *nfs_alloc_inode(struct super_block *sb)
        nfsi = (struct nfs_inode *)kmem_cache_alloc(nfs_inode_cachep, SLAB_KERNEL);
        if (!nfsi)
                return NULL;
-       nfsi->flags = NFS_INO_NEW;
+       nfsi->flags = 0;
        nfsi->mm_cred = NULL;
        return &nfsi->vfs_inode;
 }
index 8a3ce238e01cbcd2388d628f8155c2df00c198a6..f6984b0f8d2cc63cb6250015786e08463defcc0e 100644 (file)
@@ -33,7 +33,7 @@ void reiserfs_delete_inode (struct inode * inode)
     lock_kernel() ; 
 
     /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */
-    if (INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */
+    if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */
        down (&inode->i_sem); 
 
        journal_begin(&th, inode->i_sb, jbegin_count) ;
@@ -886,7 +886,7 @@ int reiserfs_get_block (struct inode * inode, sector_t block,
 // item version directly
 //
 
-// called by read_inode
+// called by read_locked_inode
 static void init_inode (struct inode * inode, struct path * path)
 {
     struct buffer_head * bh;
@@ -1117,7 +1117,7 @@ void reiserfs_update_sd (struct reiserfs_transaction_handle *th,
     return;
 }
 
-/* reiserfs_read_inode2 is called to read the inode off disk, and it
+/* reiserfs_read_locked_inode is called to read the inode off disk, and it
 ** does a make_bad_inode when things go wrong.  But, we need to make sure
 ** and clear the key in the private portion of the inode, otherwise a
 ** corresponding iput might try to delete whatever object the inode last
@@ -1128,11 +1128,6 @@ static void reiserfs_make_bad_inode(struct inode *inode) {
     make_bad_inode(inode);
 }
 
-void reiserfs_read_inode(struct inode *inode) {
-    reiserfs_make_bad_inode(inode) ;
-}
-
-
 //
 // initially this function was derived from minix or ext2's analog and
 // evolved as the prototype did
@@ -1140,26 +1135,20 @@ void reiserfs_read_inode(struct inode *inode) {
 
 int reiserfs_init_locked_inode (struct inode * inode, void *p)
 {
-    struct reiserfs_iget4_args *args = (struct reiserfs_iget4_args *)p ;
+    struct reiserfs_iget_args *args = (struct reiserfs_iget_args *)p ;
     INODE_PKEY(inode)->k_dir_id = cpu_to_le32(args->objectid);
     return 0;
 }
 
 /* looks for stat data in the tree, and fills up the fields of in-core
    inode stat data fields */
-void reiserfs_read_inode2 (struct inode * inode, void *p)
+void reiserfs_read_locked_inode (struct inode * inode, struct reiserfs_iget_args *args)
 {
     INITIALIZE_PATH (path_to_sd);
     struct cpu_key key;
-    struct reiserfs_iget4_args *args = (struct reiserfs_iget4_args *)p ;
     unsigned long dirino;
     int retval;
 
-    if (!p) {
-       reiserfs_make_bad_inode(inode) ;
-       return;
-    }
-
     dirino = args->objectid ;
 
     /* set version 1, version 2 could be used too, because stat data
@@ -1173,7 +1162,7 @@ void reiserfs_read_inode2 (struct inode * inode, void *p)
     /* look for the object's stat data */
     retval = search_item (inode->i_sb, &key, &path_to_sd);
     if (retval == IO_ERROR) {
-       reiserfs_warning ("vs-13070: reiserfs_read_inode2: "
+       reiserfs_warning ("vs-13070: reiserfs_read_locked_inode: "
                     "i/o failure occurred trying to find stat data of %K\n",
                     &key);
        reiserfs_make_bad_inode(inode) ;
@@ -1205,7 +1194,7 @@ void reiserfs_read_inode2 (struct inode * inode, void *p)
        during mount (fs/reiserfs/super.c:finish_unfinished()). */
     if( ( inode -> i_nlink == 0 ) && 
        ! REISERFS_SB(inode -> i_sb) -> s_is_unlinked_ok ) {
-           reiserfs_warning( "vs-13075: reiserfs_read_inode2: "
+           reiserfs_warning( "vs-13075: reiserfs_read_locked_inode: "
                              "dead inode read from disk %K. "
                              "This is likely to be race with knfsd. Ignore\n", 
                              &key );
@@ -1217,12 +1206,12 @@ void reiserfs_read_inode2 (struct inode * inode, void *p)
 }
 
 /**
- * reiserfs_find_actor() - "find actor" reiserfs supplies to iget4().
+ * reiserfs_find_actor() - "find actor" reiserfs supplies to iget5_locked().
  *
  * @inode:    inode from hash table to check
- * @opaque:   "cookie" passed to iget4(). This is &reiserfs_iget4_args.
+ * @opaque:   "cookie" passed to iget5_locked(). This is &reiserfs_iget_args.
  *
- * This function is called by iget4() to distinguish reiserfs inodes
+ * This function is called by iget5_locked() to distinguish reiserfs inodes
  * having the same inode numbers. Such inodes can only exist due to some
  * error condition. One of them should be bad. Inodes with identical
  * inode numbers (objectids) are distinguished by parent directory ids.
@@ -1230,7 +1219,7 @@ void reiserfs_read_inode2 (struct inode * inode, void *p)
  */
 int reiserfs_find_actor( struct inode *inode, void *opaque )
 {
-    struct reiserfs_iget4_args *args;
+    struct reiserfs_iget_args *args;
 
     args = opaque;
     /* args is already in CPU order */
@@ -1240,14 +1229,19 @@ int reiserfs_find_actor( struct inode *inode, void *opaque )
 struct inode * reiserfs_iget (struct super_block * s, const struct cpu_key * key)
 {
     struct inode * inode;
-    struct reiserfs_iget4_args args ;
+    struct reiserfs_iget_args args ;
 
     args.objectid = key->on_disk_key.k_dir_id ;
-    inode = iget4 (s, key->on_disk_key.k_objectid, 
+    inode = iget5_locked (s, key->on_disk_key.k_objectid, 
                   reiserfs_find_actor, reiserfs_init_locked_inode, (void *)(&args));
     if (!inode) 
        return ERR_PTR(-ENOMEM) ;
 
+    if (inode->i_state & I_NEW) {
+       reiserfs_read_locked_inode(inode, &args);
+       unlock_new_inode(inode);
+    }
+
     if (comp_short_keys (INODE_PKEY (inode), key) || is_bad_inode (inode)) {
        /* either due to i/o error or a stale NFS handle */
        iput (inode);
index 4bb9cbd49bce362068c002d125ae465d8e951908..83a01771ed84d03f237340125fa7e10c6d5493b4 100644 (file)
@@ -484,8 +484,6 @@ struct super_operations reiserfs_sops =
 {
   alloc_inode: reiserfs_alloc_inode,
   destroy_inode: reiserfs_destroy_inode,
-  read_inode: reiserfs_read_inode,
-  read_inode2: reiserfs_read_inode2,
   write_inode: reiserfs_write_inode,
   dirty_inode: reiserfs_dirty_inode,
   delete_inode: reiserfs_delete_inode,
@@ -1007,7 +1005,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
     int old_format = 0;
     unsigned long blocks;
     int jinit_done = 0 ;
-    struct reiserfs_iget4_args args ;
+    struct reiserfs_iget_args args ;
     struct reiserfs_super_block * rs;
     char *jdev_name;
     struct reiserfs_sb_info *sbi;
@@ -1070,12 +1068,17 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
        s->s_flags |= MS_RDONLY ;
     }
     args.objectid = REISERFS_ROOT_PARENT_OBJECTID ;
-    root_inode = iget4 (s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor, reiserfs_init_locked_inode, (void *)(&args));
+    root_inode = iget5_locked (s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor, reiserfs_init_locked_inode, (void *)(&args));
     if (!root_inode) {
        printk ("reiserfs_fill_super: get root inode failed\n");
        goto error;
     }
 
+    if (root_inode->i_state & I_NEW) {
+       reiserfs_read_locked_inode(root_inode, &args);
+       unlock_new_inode(root_inode);
+    }
+
     s->s_root = d_alloc_root(root_inode);  
     if (!s->s_root) {
        iput(root_inode);
index 50138553bb15428dd5cb411d49abbe31f4b2d686..2f82322fb04b9df96556c22af2021eb18404de9e 100644 (file)
@@ -1215,7 +1215,14 @@ extern void unlock_new_inode(struct inode *);
 extern struct inode * iget4(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *);
 static inline struct inode *iget(struct super_block *sb, unsigned long ino)
 {
-       return iget4(sb, ino, NULL, NULL, NULL);
+       struct inode *inode = iget_locked(sb, ino);
+       
+       if (inode && (inode->i_state & I_NEW)) {
+               sb->s_op->read_inode(inode);
+               unlock_new_inode(inode);
+       }
+
+       return inode;
 }
 
 extern void __iget(struct inode * inode);
index 499b246788f473a00f0cb4cc040844f819ec3c6e..a8a2259a8343d79e829452cb8e94bbc15900270a 100644 (file)
@@ -170,7 +170,6 @@ struct nfs_inode {
 #define NFS_INO_REVALIDATING   0x0004          /* revalidating attrs */
 #define NFS_IS_SNAPSHOT                0x0010          /* a snapshot file */
 #define NFS_INO_FLUSH          0x0020          /* inode is due for flushing */
-#define NFS_INO_NEW            0x0040          /* hadn't been filled yet */
 
 static inline struct nfs_inode *NFS_I(struct inode *inode)
 {
@@ -208,7 +207,6 @@ do { \
 #define NFS_FLAGS(inode)               (NFS_I(inode)->flags)
 #define NFS_REVALIDATING(inode)                (NFS_FLAGS(inode) & NFS_INO_REVALIDATING)
 #define NFS_STALE(inode)               (NFS_FLAGS(inode) & NFS_INO_STALE)
-#define NFS_NEW(inode)                 (NFS_FLAGS(inode) & NFS_INO_NEW)
 
 #define NFS_FILEID(inode)              (NFS_I(inode)->fileid)
 
index 22c5547e86bc60d3ceff72eac0b7f77a15b1c6b5..c2bfc3fd4ed5b6a14605c63ac30c6fb269e5db78 100644 (file)
@@ -1564,7 +1564,7 @@ extern struct item_operations * item_ops [TYPE_ANY + 1];
 #define B_I_POS_UNFM_POINTER(bh,ih,pos) le32_to_cpu(*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)))
 #define PUT_B_I_POS_UNFM_POINTER(bh,ih,pos, val) do {*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)) = cpu_to_le32(val); } while (0)
 
-struct reiserfs_iget4_args {
+struct reiserfs_iget_args {
     __u32 objectid ;
 } ;
 
@@ -1818,8 +1818,7 @@ void padd_item (char * item, int total_length, int length);
 
 /* inode.c */
 
-void reiserfs_read_inode (struct inode * inode) ;
-void reiserfs_read_inode2(struct inode * inode, void *p) ;
+void reiserfs_read_locked_inode(struct inode * inode, struct reiserfs_iget_args *args) ;
 int reiserfs_find_actor(struct inode * inode, void *p) ;
 int reiserfs_init_locked_inode(struct inode * inode, void *p) ;
 void reiserfs_delete_inode (struct inode * inode);