jmicron ATA: reimplement jmicron ATA quirk
[powerpc.git] / fs / gfs2 / inode.c
index 19b2736..0d6831a 100644 (file)
 #include "trans.h"
 #include "util.h"
 
-/**
- * gfs2_inode_attr_in - Copy attributes from the dinode into the VFS inode
- * @ip: The GFS2 inode (with embedded disk inode data)
- * @inode:  The Linux VFS inode
- *
- */
-
-void gfs2_inode_attr_in(struct gfs2_inode *ip)
-{
-       struct inode *inode = &ip->i_inode;
-       struct gfs2_dinode_host *di = &ip->i_di;
-
-       i_size_write(inode, di->di_size);
-       inode->i_blocks = di->di_blocks <<
-               (GFS2_SB(inode)->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT);
-}
-
 static int iget_test(struct inode *inode, void *opaque)
 {
        struct gfs2_inode *ip = GFS2_I(inode);
        struct gfs2_inum_host *inum = opaque;
 
-       if (ip && ip->i_num.no_addr == inum->no_addr)
+       if (ip->i_num.no_addr == inum->no_addr)
                return 1;
 
        return 0;
@@ -187,7 +170,9 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
         */
        ip->i_inode.i_nlink = be32_to_cpu(str->di_nlink);
        di->di_size = be64_to_cpu(str->di_size);
+       i_size_write(&ip->i_inode, di->di_size);
        di->di_blocks = be64_to_cpu(str->di_blocks);
+       gfs2_set_inode_blocks(&ip->i_inode);
        ip->i_inode.i_atime.tv_sec = be64_to_cpu(str->di_atime);
        ip->i_inode.i_atime.tv_nsec = 0;
        ip->i_inode.i_mtime.tv_sec = be64_to_cpu(str->di_mtime);
@@ -302,10 +287,8 @@ out:
  *
  * Returns: errno
  */
-
 int gfs2_change_nlink(struct gfs2_inode *ip, int diff)
 {
-       struct gfs2_sbd *sdp = ip->i_inode.i_sb->s_fs_info;
        struct buffer_head *dibh;
        u32 nlink;
        int error;
@@ -330,42 +313,34 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff)
        else
                drop_nlink(&ip->i_inode);
 
-       ip->i_inode.i_ctime.tv_sec = get_seconds();
+       ip->i_inode.i_ctime = CURRENT_TIME_SEC;
 
        gfs2_trans_add_bh(ip->i_gl, dibh, 1);
        gfs2_dinode_out(ip, dibh->b_data);
        brelse(dibh);
        mark_inode_dirty(&ip->i_inode);
 
-       if (ip->i_inode.i_nlink == 0) {
-               struct gfs2_rgrpd *rgd;
-               struct gfs2_holder ri_gh, rg_gh;
-
-               error = gfs2_rindex_hold(sdp, &ri_gh);
-               if (error)
-                       goto out;
-               error = -EIO;
-               rgd = gfs2_blk2rgrpd(sdp, ip->i_num.no_addr);
-               if (!rgd)
-                       goto out_norgrp;
-               error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &rg_gh);
-               if (error)
-                       goto out_norgrp;
-
+       if (ip->i_inode.i_nlink == 0)
                gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */
-               gfs2_glock_dq_uninit(&rg_gh);
-out_norgrp:
-               gfs2_glock_dq_uninit(&ri_gh);
-       }
-out:
+
        return error;
 }
 
 struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
 {
        struct qstr qstr;
+       struct inode *inode;
        gfs2_str2qstr(&qstr, name);
-       return gfs2_lookupi(dip, &qstr, 1, NULL);
+       inode = gfs2_lookupi(dip, &qstr, 1, NULL);
+       /* gfs2_lookupi has inconsistent callers: vfs
+        * related routines expect NULL for no entry found,
+        * gfs2_lookup_simple callers expect ENOENT
+        * and do not check for NULL.
+        */
+       if (inode == NULL)
+               return ERR_PTR(-ENOENT);
+       else
+               return inode;
 }
 
 
@@ -376,8 +351,10 @@ struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
  * @is_root: If 1, ignore the caller's permissions
  * @i_gh: An uninitialized holder for the new inode glock
  *
- * There will always be a vnode (Linux VFS inode) for the d_gh inode unless
- * @is_root is true.
+ * This can be called via the VFS filldir function when NFS is doing
+ * a readdirplus and the inode which its intending to stat isn't
+ * already in cache. In this case we must not take the directory glock
+ * again, since the readdir call will have already taken that lock.
  *
  * Returns: errno
  */
@@ -390,8 +367,9 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
        struct gfs2_holder d_gh;
        struct gfs2_inum_host inum;
        unsigned int type;
-       int error = 0;
+       int error;
        struct inode *inode = NULL;
+       int unlock = 0;
 
        if (!name->len || name->len > GFS2_FNAMESIZE)
                return ERR_PTR(-ENAMETOOLONG);
@@ -403,9 +381,12 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
                return dir;
        }
 
-       error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
-       if (error)
-               return ERR_PTR(error);
+       if (gfs2_glock_is_locked_by_me(dip->i_gl) == 0) {
+               error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
+               if (error)
+                       return ERR_PTR(error);
+               unlock = 1;
+       }
 
        if (!is_root) {
                error = permission(dir, MAY_EXEC, NULL);
@@ -420,10 +401,11 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
        inode = gfs2_inode_lookup(sb, &inum, type);
 
 out:
-       gfs2_glock_dq_uninit(&d_gh);
+       if (unlock)
+               gfs2_glock_dq_uninit(&d_gh);
        if (error == -ENOENT)
                return NULL;
-       return inode;
+       return inode ? inode : ERR_PTR(error);
 }
 
 static int pick_formal_ino_1(struct gfs2_sbd *sdp, u64 *formal_ino)
@@ -885,33 +867,10 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
        if (error)
                goto fail_gunlock;
 
-       if (inum.no_addr < dip->i_num.no_addr) {
-               gfs2_glock_dq(ghs);
-
-               error = gfs2_glock_nq_num(sdp, inum.no_addr,
-                                         &gfs2_inode_glops, LM_ST_EXCLUSIVE,
-                                         GL_SKIP, ghs + 1);
-               if (error) {
-                       return ERR_PTR(error);
-               }
-
-               gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs);
-               error = gfs2_glock_nq(ghs);
-               if (error) {
-                       gfs2_glock_dq_uninit(ghs + 1);
-                       return ERR_PTR(error);
-               }
-
-               error = create_ok(dip, name, mode);
-               if (error)
-                       goto fail_gunlock2;
-       } else {
-               error = gfs2_glock_nq_num(sdp, inum.no_addr,
-                                         &gfs2_inode_glops, LM_ST_EXCLUSIVE,
-                                         GL_SKIP, ghs + 1);
-               if (error)
-                       goto fail_gunlock;
-       }
+       error = gfs2_glock_nq_num(sdp, inum.no_addr, &gfs2_inode_glops,
+                                 LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1);
+       if (error)
+               goto fail_gunlock;
 
        error = make_dinode(dip, ghs[1].gh_gl, mode, &inum, &generation, dev);
        if (error)
@@ -1249,92 +1208,6 @@ fail:
        return error;
 }
 
-/**
- * glock_compare_atime - Compare two struct gfs2_glock structures for sort
- * @arg_a: the first structure
- * @arg_b: the second structure
- *
- * Returns: 1 if A > B
- *         -1 if A < B
- *          0 if A == B
- */
-
-static int glock_compare_atime(const void *arg_a, const void *arg_b)
-{
-       const struct gfs2_holder *gh_a = *(const struct gfs2_holder **)arg_a;
-       const struct gfs2_holder *gh_b = *(const struct gfs2_holder **)arg_b;
-       const struct lm_lockname *a = &gh_a->gh_gl->gl_name;
-       const struct lm_lockname *b = &gh_b->gh_gl->gl_name;
-
-       if (a->ln_number > b->ln_number)
-               return 1;
-       if (a->ln_number < b->ln_number)
-               return -1;
-       if (gh_a->gh_state == LM_ST_SHARED && gh_b->gh_state == LM_ST_EXCLUSIVE)
-               return 1;
-       if (gh_a->gh_state == LM_ST_SHARED && (gh_b->gh_flags & GL_ATIME))
-               return 1;
-
-       return 0;
-}
-
-/**
- * gfs2_glock_nq_m_atime - acquire multiple glocks where one may need an
- *      atime update
- * @num_gh: the number of structures
- * @ghs: an array of struct gfs2_holder structures
- *
- * Returns: 0 on success (all glocks acquired),
- *          errno on failure (no glocks acquired)
- */
-
-int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs)
-{
-       struct gfs2_holder **p;
-       unsigned int x;
-       int error = 0;
-
-       if (!num_gh)
-               return 0;
-
-       if (num_gh == 1) {
-               ghs->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC);
-               if (ghs->gh_flags & GL_ATIME)
-                       error = gfs2_glock_nq_atime(ghs);
-               else
-                       error = gfs2_glock_nq(ghs);
-               return error;
-       }
-
-       p = kcalloc(num_gh, sizeof(struct gfs2_holder *), GFP_KERNEL);
-       if (!p)
-               return -ENOMEM;
-
-       for (x = 0; x < num_gh; x++)
-               p[x] = &ghs[x];
-
-       sort(p, num_gh, sizeof(struct gfs2_holder *), glock_compare_atime,NULL);
-
-       for (x = 0; x < num_gh; x++) {
-               p[x]->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC);
-
-               if (p[x]->gh_flags & GL_ATIME)
-                       error = gfs2_glock_nq_atime(p[x]);
-               else
-                       error = gfs2_glock_nq(p[x]);
-
-               if (error) {
-                       while (x--)
-                               gfs2_glock_dq(p[x]);
-                       break;
-               }
-       }
-
-       kfree(p);
-       return error;
-}
-
-
 static int
 __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
 {