From: Steven Whitehouse <swhiteho@redhat.com>
To: linux-kernel@vger.kernel.org, cluster-devel@redhat.com
Cc: Steven Whitehouse <swhiteho@redhat.com>
Subject: [PATCH 22/32] GFS2: When adding a new dir entry, inc link count if it is a subdir
Date: Thu, 19 May 2011 09:47:17 +0100 [thread overview]
Message-ID: <1305794847-3291-23-git-send-email-swhiteho@redhat.com> (raw)
In-Reply-To: <1305794847-3291-1-git-send-email-swhiteho@redhat.com>
This adds an increment of the link count when we add a new directory
entry, if that entry is itself a directory. This means that we no
longer need separate code to perform this operation.
Now that both adding and removing directory entries automatically
update the parent directory's link count if required, that makes
the code shorter and simpler than before.
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 4102651..091ee47 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -1597,7 +1597,7 @@ static int dir_new_leaf(struct inode *inode, const struct qstr *name)
*/
int gfs2_dir_add(struct inode *inode, const struct qstr *name,
- const struct gfs2_inode *nip, unsigned type)
+ const struct gfs2_inode *nip)
{
struct gfs2_inode *ip = GFS2_I(inode);
struct buffer_head *bh;
@@ -1613,7 +1613,7 @@ int gfs2_dir_add(struct inode *inode, const struct qstr *name,
return PTR_ERR(dent);
dent = gfs2_init_dirent(inode, dent, name, bh);
gfs2_inum_out(nip, dent);
- dent->de_type = cpu_to_be16(type);
+ dent->de_type = cpu_to_be16(IF2DT(nip->i_inode.i_mode));
if (ip->i_diskflags & GFS2_DIF_EXHASH) {
leaf = (struct gfs2_leaf *)bh->b_data;
be16_add_cpu(&leaf->lf_entries, 1);
@@ -1625,6 +1625,8 @@ int gfs2_dir_add(struct inode *inode, const struct qstr *name,
gfs2_trans_add_bh(ip->i_gl, bh, 1);
ip->i_entries++;
ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
+ if (S_ISDIR(nip->i_inode.i_mode))
+ inc_nlink(&ip->i_inode);
gfs2_dinode_out(ip, bh->b_data);
brelse(bh);
error = 0;
diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h
index 66831f1..e686af1 100644
--- a/fs/gfs2/dir.h
+++ b/fs/gfs2/dir.h
@@ -22,7 +22,7 @@ extern struct inode *gfs2_dir_search(struct inode *dir,
extern int gfs2_dir_check(struct inode *dir, const struct qstr *filename,
const struct gfs2_inode *ip);
extern int gfs2_dir_add(struct inode *inode, const struct qstr *filename,
- const struct gfs2_inode *ip, unsigned int type);
+ const struct gfs2_inode *ip);
extern int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry);
extern int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
filldir_t filldir);
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 5a02606..a8c14c9 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -362,52 +362,6 @@ int gfs2_inode_refresh(struct gfs2_inode *ip)
return error;
}
-/**
- * gfs2_change_nlink - Change nlink count on inode
- * @ip: The GFS2 inode
- * @diff: The change in the nlink count required
- *
- * Returns: errno
- */
-int gfs2_change_nlink(struct gfs2_inode *ip, int diff)
-{
- struct buffer_head *dibh;
- u32 nlink;
- int error;
-
- BUG_ON(diff != 1 && diff != -1);
- nlink = ip->i_inode.i_nlink + diff;
-
- /* If we are reducing the nlink count, but the new value ends up being
- bigger than the old one, we must have underflowed. */
- if (diff < 0 && nlink > ip->i_inode.i_nlink) {
- if (gfs2_consist_inode(ip))
- gfs2_dinode_print(ip);
- return -EIO;
- }
-
- error = gfs2_meta_inode_buffer(ip, &dibh);
- if (error)
- return error;
-
- if (diff > 0)
- inc_nlink(&ip->i_inode);
- else
- drop_nlink(&ip->i_inode);
-
- ip->i_inode.i_ctime = CURRENT_TIME;
-
- 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)
- gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */
-
- return error;
-}
-
struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
{
struct qstr qstr;
@@ -723,7 +677,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
goto fail_quota_locks;
}
- error = gfs2_dir_add(&dip->i_inode, name, ip, IF2DT(ip->i_inode.i_mode));
+ error = gfs2_dir_add(&dip->i_inode, name, ip);
if (error)
goto fail_end_trans;
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index 8d1344a..f9b8289 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -106,7 +106,6 @@ extern struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr, int nonbl
extern int gfs2_inode_refresh(struct gfs2_inode *ip);
-extern int gfs2_change_nlink(struct gfs2_inode *ip, int diff);
extern struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
int is_root);
extern struct inode *gfs2_createi(struct gfs2_holder *ghs,
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index 765da06..6b8c2bd 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -235,7 +235,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
if (error)
goto out_end_trans;
- error = gfs2_dir_add(dir, &dentry->d_name, ip, IF2DT(inode->i_mode));
+ error = gfs2_dir_add(dir, &dentry->d_name, ip);
if (error)
goto out_brelse;
@@ -554,9 +554,6 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
brelse(dibh);
}
- error = gfs2_change_nlink(dip, +1);
- gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
-
gfs2_trans_end(sdp);
if (dip->i_alloc->al_rgd)
gfs2_inplace_release(dip);
@@ -857,10 +854,6 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
}
if (dir_rename) {
- error = gfs2_change_nlink(ndip, +1);
- if (error)
- goto out_end_trans;
-
error = gfs2_dir_mvino(ip, &gfs2_qdotdot, ndip, DT_DIR);
if (error)
goto out_end_trans;
@@ -879,7 +872,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
if (error)
goto out_end_trans;
- error = gfs2_dir_add(ndir, &ndentry->d_name, ip, IF2DT(ip->i_inode.i_mode));
+ error = gfs2_dir_add(ndir, &ndentry->d_name, ip);
if (error)
goto out_end_trans;
--
1.7.4
next prev parent reply other threads:[~2011-05-19 9:10 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-19 8:46 GFS2: Pre-pull patch posting (merge window) Steven Whitehouse
2011-05-19 8:46 ` [PATCH 01/32] GFS2: Dump better debug info if a bitmap inconsistency is detected Steven Whitehouse
2011-05-19 8:46 ` [PATCH 02/32] GFS2: remove *leaf_call_t and simplify leaf_dealloc Steven Whitehouse
2011-05-19 8:46 ` [PATCH 03/32] GFS2: Combine transaction from gfs2_dir_exhash_dealloc Steven Whitehouse
2011-05-19 8:46 ` [PATCH 04/32] GFS2: pass leaf_bh into leaf_dealloc Steven Whitehouse
2011-05-19 8:47 ` [PATCH 05/32] GFS2: move function foreach_leaf to gfs2_dir_exhash_dealloc Steven Whitehouse
2011-05-19 8:47 ` [PATCH 06/32] GFS2: Make ->write_inode() really write Steven Whitehouse
2011-05-19 8:47 ` [PATCH 07/32] GFS2: Use filemap_fdatawrite() to write back the AIL Steven Whitehouse
2011-05-19 8:47 ` [PATCH 08/32] GFS2: Alter point of entry to glock lru list for glocks with an address_space Steven Whitehouse
2011-05-19 8:47 ` [PATCH 09/32] GFS2: Remove unused macro Steven Whitehouse
2011-05-19 8:47 ` [PATCH 10/32] GFS2: Clean up fsync() Steven Whitehouse
2011-05-19 8:47 ` [PATCH 11/32] GFS2: Improve tracing support (adds two flags) Steven Whitehouse
2011-05-19 8:47 ` [PATCH 12/32] GFS2: Optimise glock lru and end of life inodes Steven Whitehouse
2011-05-19 8:47 ` [PATCH 13/32] GFS2: Make writeback more responsive to system conditions Steven Whitehouse
2011-05-19 8:47 ` [PATCH 14/32] GFS2: Add an AIL writeback tracepoint Steven Whitehouse
2011-05-19 8:47 ` [PATCH 15/32] GFS2: make sure fallocate bytes is a multiple of blksize Steven Whitehouse
2011-05-19 8:47 ` [PATCH 16/32] GFS2: Fix ail list traversal Steven Whitehouse
2011-05-19 8:47 ` [PATCH 17/32] GFS2: Improve bug trap code in ->releasepage() Steven Whitehouse
2011-05-19 8:47 ` [PATCH 18/32] GFS2: Double check link count under glock Steven Whitehouse
2011-05-19 8:47 ` [PATCH 19/32] GFS2: Don't use a try lock when promoting to a higher mode Steven Whitehouse
2011-05-19 8:47 ` [PATCH 20/32] GFS2: Don't use gfs2_change_nlink in link syscall Steven Whitehouse
2011-05-19 8:47 ` [PATCH 21/32] GFS2: Make gfs2_dir_del update link count when required Steven Whitehouse
2011-05-19 8:47 ` Steven Whitehouse [this message]
2011-05-19 8:47 ` [PATCH 23/32] GFS2: Remove gfs2_dinode_print() function Steven Whitehouse
2011-05-19 8:47 ` [PATCH 24/32] GFS2: Move gfs2_refresh_inode() and friends into glops.c Steven Whitehouse
2011-05-19 8:47 ` [PATCH 25/32] GFS2: Move most of the remaining inode.c into ops_inode.c Steven Whitehouse
2011-05-19 8:47 ` [PATCH 26/32] GFS2: Move final part of inode.c into super.c Steven Whitehouse
2011-05-19 8:47 ` [PATCH 27/32] GFS2: Inode.c is empty now, remove it Steven Whitehouse
2011-05-19 8:47 ` [PATCH 28/32] GFS2: Rename ops_inode.c to inode.c Steven Whitehouse
2011-05-19 8:47 ` [PATCH 29/32] GFS2: Use UUID field in generic superblock Steven Whitehouse
2011-05-19 8:47 ` [PATCH 30/32] GFS2: Clean up mkdir Steven Whitehouse
2011-05-19 8:47 ` [PATCH 31/32] GFS2: Clean up symlink creation Steven Whitehouse
2011-05-19 8:47 ` [PATCH 32/32] GFS2: Move all locking inside the inode creation function Steven Whitehouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1305794847-3291-23-git-send-email-swhiteho@redhat.com \
--to=swhiteho@redhat.com \
--cc=cluster-devel@redhat.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®