Skip to contentSkip to conversation

GFS2: Increase i_writecount during gfs2_setattr_chown

PATCH New Bob Peterson 3 participants 4 messages Jan 6, 2014 – Jan 7, 2014 1 message not in the archive GFS2 file system

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 GFS2: Increase i_writecount during gfs2_setattr_chown

In reply to a message not in the archive

Hi,

This patch calls get_write_access in function gfs2_setattr_chown, which merely increases inode->i_writecount for the duration of the function. That will ensure that any file closes won't delete the inode's multi-block reservation while the function is running. It also ensures that a multi-block reservation exists when needed for quota change operations during the chown.

Regards,

Bob Peterson
Red Hat File Systems

---

fs/gfs2/inode.c +15 -1
index 7119504..87bc229 100644
@@ -1607,10 +1607,22 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
 	if (!(attr->ia_valid & ATTR_GID) || gid_eq(ogid, ngid))
 		ogid = ngid = NO_GID_QUOTA_CHANGE;
 
-	error = gfs2_quota_lock(ip, nuid, ngid);
+	error = get_write_access(inode);
 	if (error)
 		return error;
 
+	error = gfs2_rs_alloc(ip);
+	if (error)
+		goto out;
+
+	error = gfs2_rindex_update(sdp);
+	if (error)
+		goto out;
+
+	error = gfs2_quota_lock(ip, nuid, ngid);
+	if (error)
+		goto out;
+
 	if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
 	    !gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
 		error = gfs2_quota_check(ip, nuid, ngid);
@@ -1637,6 +1649,8 @@ out_end_trans:
 	gfs2_trans_end(sdp);
 out_gunlock_q:
 	gfs2_quota_unlock(ip);
+out:
+	put_write_access(inode);
 	return error;
 }
 
#2 lore raw

PATCH 1/1 GFS2: Increase i_writecount during gfs2_setattr_chown

Hi,

I've added this to the -nmw git tree. Thanks,

Steve.

Quoted 54 lines · Bob Peterson

Hi,

This patch calls get_write_access in function gfs2_setattr_chown, which merely increases inode->i_writecount for the duration of the function. That will ensure that any file closes won't delete the inode's multi-block reservation while the function is running. It also ensures that a multi-block reservation exists when needed for quota change operations during the chown.

Regards,

Bob Peterson
Red Hat File Systems

---

fs/gfs2/inode.c +15 -1
index 7119504..87bc229 100644
@@ -1607,10 +1607,22 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
 	if (!(attr->ia_valid & ATTR_GID) || gid_eq(ogid, ngid))
 		ogid = ngid = NO_GID_QUOTA_CHANGE;
 
-	error = gfs2_quota_lock(ip, nuid, ngid);
+	error = get_write_access(inode);
 	if (error)
 		return error;
 
+	error = gfs2_rs_alloc(ip);
+	if (error)
+		goto out;
+
+	error = gfs2_rindex_update(sdp);
+	if (error)
+		goto out;
+
+	error = gfs2_quota_lock(ip, nuid, ngid);
+	if (error)
+		goto out;
+
 	if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
 	    !gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
 		error = gfs2_quota_check(ip, nuid, ngid);
@@ -1637,6 +1649,8 @@ out_end_trans:
 	gfs2_trans_end(sdp);
 out_gunlock_q:
 	gfs2_quota_unlock(ip);
+out:
+	put_write_access(inode);
 	return error;
 }
 
#3 lore raw

PATCH 1/1 GFS2: Increase i_writecount during gfs2_setattr_chown

In reply to Bob Peterson
Quoted 8 lines · Bob Peterson

Hi,

This patch calls get_write_access in function gfs2_setattr_chown, which merely increases inode->i_writecount for the duration of the function. That will ensure that any file closes won't delete the inode's multi-block reservation while the function is running. It also ensures that a multi-block reservation exists when needed for quota change operations during the chown.

Can you explain how gfs2 (ab-)uses i_writecount in the allocator? i_writecunt has very complicated semantics including negative values to deal with mappings for executables, and I can't really see how these high-level semantics interact well with a block allocator.

#4 lore raw

PATCH 1/1 GFS2: Increase i_writecount during gfs2_setattr_chown

----- Original Message -----

| On Mon, Jan 06, 2014 at 05:16:01PM -0500, Bob Peterson wrote:
| > Hi,
| > 
| > This patch calls get_write_access in function gfs2_setattr_chown,
| > which merely increases inode->i_writecount for the duration of the
| > function. That will ensure that any file closes won't delete the
| > inode's multi-block reservation while the function is running.
| > It also ensures that a multi-block reservation exists when needed
| > for quota change operations during the chown.
| 
| Can you explain how gfs2 (ab-)uses i_writecount in the allocator?
| i_writecunt has very complicated semantics including negative values
| to deal with mappings for executables, and I can't really see how these
| high-level semantics interact well with a block allocator.
| 

Hi,

GFS2's allocator doesn't use i_writecount per se.

With GFS2, the last person to close a file will free the inode's multi-block reservation structure (struct gfs2_blkreserv), which is used by the allocator for reserving blocks in order to reduce fragmentation. For convenience sake (and to not overly bloat the inode structure itself), that structure is sometimes used for ancillary things, like quota manipulations. In my patch, the i_writecount is merely used to prevent file closes from deleting the multi-block reservation structures during that particular use by the GFS2 quota code.

Regards,

Bob Peterson
Red Hat File Systems