Skip to contentSkip to conversation

cluster/gfs-kernel/src/gfs daemon.c gfs_ondisk ...

Cluster-devel [email protected] 1 participant 1 message Mar 13, 2007

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/cluster
Module name: cluster
Branch: RHEL4
Changes by: wcheng at sourceware.org 2007-03-13 21:21:21

Modified files:
gfs-kernel/src/gfs: daemon.c gfs_ondisk.h incore.h ioctl.c
ops_fstype.c ops_super.c rgrp.c rgrp.h super.c super.h

Log message:
Bugzilla 220622: backport GFS2 statfs() implementation to GFS1.

There are few compromises made while porting GFS2 approach over, mostly to avoid on-disk structure changes. GFS2 allocates (number-of-nodes + 1) physical files into disk during mkfs time but GFS1 only has one extra space (the unused license file) for this purpose. We deviate from GFS2 by writing the local per-node changes into a memory buffer.

Doing a "df" on a quiet filesystem now results:

dhcp145 (1 cpu HP): old df took 0.875 seconds, new df 0.008 second dhcp146 (4 cpus DELL): old df took 0.808 seconds, new df 0.006 second.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs-kernel/src/gfs/daemon.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.5&r2=1.5.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs-kernel/src/gfs/gfs_ondisk.h.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.7.2.1&r2=1.7.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs-kernel/src/gfs/incore.h.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.17.2.8&r2=1.17.2.9
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs-kernel/src/gfs/ioctl.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.7.2.6&r2=1.7.2.7
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs-kernel/src/gfs/ops_fstype.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.13.2.3&r2=1.13.2.4
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs-kernel/src/gfs/ops_super.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.12.2.5&r2=1.12.2.6
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs-kernel/src/gfs/rgrp.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.14.2.3&r2=1.14.2.4
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs-kernel/src/gfs/rgrp.h.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.3&r2=1.3.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs-kernel/src/gfs/super.c.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.12.2.7&r2=1.12.2.8
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs-kernel/src/gfs/super.h.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.2&r2=1.2.2.1

gfs-kernel/src/gfs/daemon.c +13 -0
@@ -207,6 +207,19 @@
 	complete(&sdp->sd_thread_completion);
 
 	for (;;) {
+		/* Update statfs file */
+		if (gfs_tune_get(sdp, gt_statfs_fast) &&
+		    time_after_eq(jiffies,
+				  sdp->sd_statfs_sync_time +
+				  gfs_tune_get(sdp, gt_statfs_fast) * HZ)) {
+			error = gfs_statfs_sync(sdp);
+			if (error &&
+			    error != -EROFS &&
+			    !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
+				printk("GFS: fsid=%s: statfs: error = %d\n",
+				       sdp->sd_fsname, error);
+			sdp->sd_statfs_sync_time = jiffies;
+		}
 		/* Update quota file */
 		if (time_after_eq(jiffies,
 				  sdp->sd_quota_sync_time +
gfs-kernel/src/gfs/gfs_ondisk.h +25 -0
@@ -616,6 +616,31 @@
 	uint32_t ea_pad;
 };
 
+/*
+ * Statfs change
+ * Describes an change to the pool of free and allocated
+ * blocks.
+ */
+
+struct gfs_statfs_change {
+	__be64 sc_total;
+	__be64 sc_free;
+	__be64 sc_dinodes;
+};
+
+/*
+struct gfs_statfs_change_host {
+	__u64 sc_total;
+	__u64 sc_free;
+	__u64 sc_dinodes;
+};
+*/
+struct gfs_statfs_change_host {
+	int64_t sc_total;
+	int64_t sc_free;
+	int64_t sc_dinodes;
+};
+
 /*  Endian functions  */
 
 #define GFS_ENDIAN_BIG
gfs-kernel/src/gfs/incore.h +8 -0
@@ -893,6 +893,7 @@
 	unsigned int gt_greedy_quantum;
 	unsigned int gt_greedy_max;
 	unsigned int gt_rgrp_try_threshold;
+	unsigned int gt_statfs_fast;
 };
 
 /*
@@ -963,6 +964,13 @@
 
 	struct gfs_tune sd_tune;	/* Filesystem tuning structure */
 
+	/* statfs */
+	struct inode *sd_statfs_inode;
+	spinlock_t sd_statfs_spin;
+	struct gfs_statfs_change_host sd_statfs_master;
+	struct gfs_statfs_change_host sd_statfs_local;
+	unsigned long sd_statfs_sync_time; 
+
 	/* Resource group stuff */
 
 	struct gfs_inode *sd_riinode;	/* Resource Index (rindex) inode */
gfs-kernel/src/gfs/ioctl.c +11 -2
@@ -483,6 +483,7 @@
         gfs_printf("greedy_quantum %u\n", gt->gt_greedy_quantum);
         gfs_printf("greedy_max %u\n", gt->gt_greedy_max);
         gfs_printf("rgrp_try_threshold %u\n", gt->gt_rgrp_try_threshold);
+        gfs_printf("statfs_fast %u\n", gt->gt_statfs_fast);
 
         error = 0;
 
@@ -513,6 +514,7 @@
 	struct gfs_tune *gt = &sdp->sd_tune;
  	char param[ARG_SIZE], value[ARG_SIZE];
 	unsigned int x;
+	int error;
 
 	if (!capable(CAP_SYS_ADMIN))
                 return -EACCES;
@@ -752,6 +754,15 @@
 			return -EINVAL;
 		tune_set(gt_rgrp_try_threshold, x);
 
+	} else if (strcmp(param, "statfs_fast") == 0) {
+		if (sscanf(value, "%u", &x) != 1)
+			return -EINVAL;
+		error = gfs_statfs_init(sdp, x);
+		if (error) 
+			return error;
+		else 
+			tune_set(gt_statfs_fast, x);
+
 	} else
 		return -EINVAL;
 
@@ -1496,5 +1507,3 @@
 
 	return error;
 }
-
-
gfs-kernel/src/gfs/ops_fstype.c +10 -1
@@ -100,6 +100,8 @@
 	spin_lock_init(&sdp->sd_rg_recent_lock);
 	spin_lock_init(&sdp->sd_rg_forward_lock);
 
+	spin_lock_init(&sdp->sd_statfs_spin);
+
 	for (x = 0; x < GFS_GL_HASH_SIZE; x++) {
 		sdp->sd_gl_hash[x].hb_lock = RW_LOCK_UNLOCKED;
 		INIT_LIST_HEAD(&sdp->sd_gl_hash[x].hb_list);
@@ -472,9 +474,16 @@
 
 	/*  Read in the license inode  */
 
+	/* Piggy back fast df on this inode location 
+	 * sb->sb_quota_di.no_formal_ino = jindex_dinode + 2;
+	 * sb->sb_quota_di.no_addr = jindex_dinode + 2;
+	 * sb->sb_license_di.no_formal_ino = jindex_dinode + 3;
+	 * sb->sb_license_di.no_addr = jindex_dinode + 3;
+	 */
+
 	error = gfs_get_linode(sdp);
 	if (error) {
-		printk("GFS: fsid=%s: can't get license file inode: %d\n",
+		printk("GFS: fsid=%s: can't get license/statfs file inode: %d\n",
 		       sdp->sd_fsname, error);
 		goto fail_qi_free;
 	}
gfs-kernel/src/gfs/ops_super.c +3 -0
@@ -283,6 +283,9 @@
 
 	atomic_inc(&sdp->sd_ops_super);
 
+	if (gfs_tune_get(sdp, gt_statfs_fast)) 
+		return(gfs_statfs_fast(sdp, (void *)buf));
+
 	error = gfs_stat_gfs(sdp, &sg, TRUE);
 	if (error)
 		return error;
gfs-kernel/src/gfs/rgrp.c +19 -0
@@ -18,6 +18,7 @@
 #include <asm/semaphore.h>
 #include <linux/completion.h>
 #include <linux/buffer_head.h>
+#include <linux/types.h>
 
 #include "gfs.h"
 #include "bits.h"
@@ -1657,6 +1658,9 @@
 	al->al_alloced_data++;
 
 	gfs_trans_add_quota(sdp, +1, ip->i_di.di_uid, ip->i_di.di_gid);
+	
+	/* total=0, free=-1, dinodes=0 */
+	gfs_statfs_modify(sdp, 0, -1, 0);
 }
 
 /**
@@ -1711,6 +1715,9 @@
 
 	gfs_trans_add_quota(sdp, +1, ip->i_di.di_uid, ip->i_di.di_gid);
 
+	/* total=0, free=-1, dinode=0 */
+	gfs_statfs_modify(sdp, 0, -1, 0);
+
 	return 0;
 }
 
@@ -1726,6 +1733,7 @@
 int
 gfs_dialloc(struct gfs_inode *dip, uint64_t *block)
 {
+	struct gfs_sbd *sdp = dip->i_sbd;
 	struct gfs_alloc *al = dip->i_alloc;
 	struct gfs_rgrpd *rgd = al->al_rgd;
 	uint32_t goal, blk;
@@ -1765,6 +1773,9 @@
 	al->al_alloced_di++;
 	al->al_alloced_meta++;
 
+	/* total=0, free=-1, dinodes=1 */
+	gfs_statfs_modify(sdp, 0, -1, +1);
+
 	return error;
 }
 
@@ -1797,6 +1808,8 @@
 	gfs_trans_add_quota(sdp, -(int64_t)blen,
 			    ip->i_di.di_uid,
 			    ip->i_di.di_gid);
+	/* total=0, free=+blen, dinodes=0 */
+	gfs_statfs_modify(sdp, 0, blen, 0); 
 }
 
 /**
@@ -1831,6 +1844,9 @@
 	gfs_trans_add_bh(rgd->rd_gl, rgd->rd_bh[0]);
 	gfs_rgrp_out(&rgd->rd_rg, rgd->rd_bh[0]->b_data);
 
+	/* total=0, free=blen, dinode=0 */
+	gfs_statfs_modify(sdp, 0, blen, 0);
+
 	gfs_trans_add_quota(sdp, -(int64_t)blen,
 			    ip->i_di.di_uid,
 			    ip->i_di.di_gid);
@@ -1865,6 +1881,9 @@
 
 	gfs_trans_add_bh(rgd->rd_gl, rgd->rd_bh[0]);
 	gfs_rgrp_out(&rgd->rd_rg, rgd->rd_bh[0]->b_data);
+
+	/* total=0, free=1, dinodes=-1 */
+	gfs_statfs_modify(rgd->rd_sbd, 0, +1, -1);
 }
 
 /**
gfs-kernel/src/gfs/rgrp.h +4 -0
@@ -57,6 +57,10 @@
 void gfs_difree_uninit(struct gfs_rgrpd *rgd, uint64_t addr);
 void gfs_difree(struct gfs_rgrpd *rgd, struct gfs_inode *ip);
 
+extern void gfs_statfs_modify(struct gfs_sbd *sdp,
+                                int64_t total,
+                                int64_t free,
+                                int64_t dinodes);
 /*
  * gfs_rgrp_list
  *
gfs-kernel/src/gfs/super.c +202 -0

235 lines not on this page · raw message

gfs-kernel/src/gfs/super.h +4 -0
@@ -42,6 +42,10 @@
 int gfs_make_fs_rw(struct gfs_sbd *sdp);
 int gfs_make_fs_ro(struct gfs_sbd *sdp);
 
+int gfs_statfs_init(struct gfs_sbd *sdp, int flag);
+int gfs_statfs_sync(struct gfs_sbd *sdp);
+int gfs_statfs_fast(struct gfs_sbd *sdp, void *buf);
+
 struct gfs_stat_gfs {
 	uint64_t sg_total_blocks;
 	uint64_t sg_free;