Re: [ogfs-dev]RFC: Reclaim the excess freemeta blocks
Attachment is the initial patch for reclaiming excess freemeta
blocks.(without man page update)
Any comments or suggestions ?
Thanks,
Stan
--
Opinions expressed are those of the author and do not represent Intel
Corporation
? autom4te-2.53.cache
? src/cscope.out
Index: src/fs/bits.c
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/bits.c,v
retrieving revision 1.6
diff -r1.6 bits.c
30c30
< /* n */ 0, 1, 0, 0,
---
> /* n */ 0, 1, 1, 0,
Index: src/fs/blklist.c
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/blklist.c,v
retrieving revision 1.30
diff -r1.30 blklist.c
1996a1997,2079
>
> /**
> * ogfs_reclaim_freemeta - reclaim excess free metadata block
> * @sdp: the filesystem
> * @arg:
> * */
>
> int ogfs_reclaim_freemeta(ogfs_sbd_t *sdp, void *arg)
> {
> int error, rnum, excess, s_excess;
> unsigned int buf;
> uint32 length,block;
> ogfs_bitmap_t *bits = NULL;
> ogfs_rgrpd_t *rgd;
>
> error = ogfs_rindex_hold(sdp);
> if (error) {
> return error;
> }
>
> for ( rnum = 0 ; rnum < sdp->sd_rgcount; rnum++) {
>
> rgd = ogfs_rgrpd_get_by_num(sdp, rnum);
> if (rgd == NULL)
> continue;
>
> error = ogfs_glock_rg(rgd, 0);
> if (error) {
> ogfs_rgrpd_put(rgd);
> continue;
> }
>
> if (test_and_clear_bit(RDF_SYNC_B4_ALLOC, &rgd->rd_flags))
> ogfs_log_flush(sdp, rgd->rd_gl);
>
> length = rgd->rd_ri.ri_length;
> excess = rgd->rd_rg.rg_freemeta - OGFS_META_CLUMP;
> if (excess > 0) {
> error = ogfs_trans_begin(sdp, TRANS_BMAP, length + 1, 0);
> if (error) {
> ogfs_gunlock_rg(rgd, 0);
> ogfs_rgrpd_put(rgd);
> ogfs_rindex_release(sdp);
> return error;
> }
> } else {
> ogfs_gunlock_rg(rgd, 0);
> ogfs_rgrpd_put(rgd);
> continue;
> }
>
> s_excess = excess;
>
> for (buf = 0; buf < length; buf++) {
> bits = &rgd->rd_bits[buf];
> while (excess) {
> block = ogfs_bitfit(BH_DATA(rgd->rd_bh[buf]) + bits->bi_offset,
> bits->bi_len, 0, OGFS_BLKST_FREEMETA);
> if (block != BFITNOENT) {
> excess--;
> ogfs_setbit(BH_DATA(rgd->rd_bh[buf]) + bits->bi_offset,
> bits->bi_len, block, OGFS_BLKST_FREE);
> } else {
> break;
> }
> }
> ogfs_trans_add_bh(sdp, rgd->rd_bh[buf]);
> }
> rgd->rd_rg.rg_freemeta -= (s_excess - excess);
> rgd->rd_rg.rg_free += (s_excess - excess);
> ogfs_trans_add_bh(sdp, rgd->rd_bh[0]);
> ogfs_rgrp_out(&rgd->rd_rg, BH_DATA(rgd->rd_bh[0]));
> rgrp_lvb_own(rgd);
> set_bit(RDF_SYNC_B4_ALLOC, &rgd->rd_flags);
> ogfs_trans_end(sdp);
> ogfs_gunlock_rg(rgd, 0);
> ogfs_rgrpd_put(rgd);
> }
>
> ogfs_rindex_release(sdp);
> return error;
>
> }
Index: src/fs/blklist.h
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/blklist.h,v
retrieving revision 1.7
diff -r1.7 blklist.h
64a65
> int ogfs_reclaim_freemeta(ogfs_sbd_t *sdp, void *arg);
Index: src/fs/ioctl.c
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/ioctl.c,v
retrieving revision 1.17
diff -r1.17 ioctl.c
24a25
> #include "blklist.h"
415a417,427
> }
>
> /**
> * ogfs_reclaim_freemeta_ioctl - ioctl function for reclaiming excess
> * free metadata block
> * @sdp: the filesystem
> * @arg:
> * */
> int ogfs_reclaim_freemeta_ioctl(ogfs_sbd_t *sdp, void *arg)
> {
> return ogfs_reclaim_freemeta(sdp, arg);
Index: src/fs/ioctl.h
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/ioctl.h,v
retrieving revision 1.4
diff -r1.4 ioctl.h
28a29,30
> int ogfs_reclaim_freemeta_ioctl(ogfs_sbd_t * sdp, void *arg);
>
Index: src/fs/ogfs_ioctl.h
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/ogfs_ioctl.h,v
retrieving revision 1.3
diff -r1.3 ogfs_ioctl.h
35a36,37
> #define OGFS_RECLAIM_FREEMETA _GFSC_(13)
>
Index: src/fs/arch_linux_2_4/file.c
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/arch_linux_2_4/file.c,v
retrieving revision 1.17
diff -r1.17 file.c
883a884,889
> case OGFS_RECLAIM_FREEMETA:
> lock_kernel();
> error = ogfs_reclaim_freemeta_ioctl(sdp, (void *) arg);
> unlock_kernel();
> break;
>
Index: src/tools/ogfs_tool/main.c
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/tools/ogfs_tool/main.c,v
retrieving revision 1.8
diff -r1.8 main.c
69a70,72
> "Reclaim the excess free metadata blocks:\n",
> " ogfs_tool reclaim <filename>\n",
> "\n",
275a279,313
> /*
> *
> * void reclaim()
> *
> * Description:
> * This routine uses an ioctl command to ask OGFS reclaim the excess free
> * metadata blocks.
> *
> * Input(s):
> * argc -
> * **argv -
> *
> */
>
> void reclaim(int argc, char **argv)
> {
> int fd;
>
>
> if (argc != 3)
> die("not enough arguments\n");
>
>
> fd = open(argv[2], O_RDONLY);
> if (fd < 0)
> die("can't open %s: %s\n", argv[2], strerror(errno));
>
>
> if (ioctl(fd, OGFS_RECLAIM_FREEMETA, NULL) < 0)
> die("error doing ioctl: %s\n", strerror(errno));
>
>
> close(fd);
> }
>
306a345,346
> } else if (strcmp(argv[1], "reclaim") == 0) {
> reclaim(argc, argv);
? autom4te-2.53.cache
? src/cscope.out
Index: src/fs/bits.c
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/bits.c,v
retrieving revision 1.6
diff -r1.6 bits.c
30c30
< /* n */ 0, 1, 0, 0,
---
> /* n */ 0, 1, 1, 0,
Index: src/fs/blklist.c
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/blklist.c,v
retrieving revision 1.30
diff -r1.30 blklist.c
1996a1997,2079
>
> /**
> * ogfs_reclaim_freemeta - reclaim excess free metadata block
> * @sdp: the filesystem
> * @arg:
> * */
>
> int ogfs_reclaim_freemeta(ogfs_sbd_t *sdp, void *arg)
> {
> int error, rnum, excess, s_excess;
> unsigned int buf;
> uint32 length,block;
> ogfs_bitmap_t *bits = NULL;
> ogfs_rgrpd_t *rgd;
>
> error = ogfs_rindex_hold(sdp);
> if (error) {
> return error;
> }
>
> for ( rnum = 0 ; rnum < sdp->sd_rgcount; rnum++) {
>
> rgd = ogfs_rgrpd_get_by_num(sdp, rnum);
> if (rgd == NULL)
> continue;
>
> error = ogfs_glock_rg(rgd, 0);
> if (error) {
> ogfs_rgrpd_put(rgd);
> continue;
> }
>
> if (test_and_clear_bit(RDF_SYNC_B4_ALLOC, &rgd->rd_flags))
> ogfs_log_flush(sdp, rgd->rd_gl);
>
> length = rgd->rd_ri.ri_length;
> excess = rgd->rd_rg.rg_freemeta - OGFS_META_CLUMP;
> if (excess > 0) {
> error = ogfs_trans_begin(sdp, TRANS_BMAP, length + 1, 0);
> if (error) {
> ogfs_gunlock_rg(rgd, 0);
> ogfs_rgrpd_put(rgd);
> ogfs_rindex_release(sdp);
> return error;
> }
> } else {
> ogfs_gunlock_rg(rgd, 0);
> ogfs_rgrpd_put(rgd);
> continue;
> }
>
> s_excess = excess;
>
> for (buf = 0; buf < length; buf++) {
> bits = &rgd->rd_bits[buf];
> while (excess) {
> block = ogfs_bitfit(BH_DATA(rgd->rd_bh[buf]) + bits->bi_offset,
> bits->bi_len, 0, OGFS_BLKST_FREEMETA);
> if (block != BFITNOENT) {
> excess--;
> ogfs_setbit(BH_DATA(rgd->rd_bh[buf]) + bits->bi_offset,
> bits->bi_len, block, OGFS_BLKST_FREE);
> } else {
> break;
> }
> }
> ogfs_trans_add_bh(sdp, rgd->rd_bh[buf]);
> }
> rgd->rd_rg.rg_freemeta -= (s_excess - excess);
> rgd->rd_rg.rg_free += (s_excess - excess);
> ogfs_trans_add_bh(sdp, rgd->rd_bh[0]);
> ogfs_rgrp_out(&rgd->rd_rg, BH_DATA(rgd->rd_bh[0]));
> rgrp_lvb_own(rgd);
> set_bit(RDF_SYNC_B4_ALLOC, &rgd->rd_flags);
> ogfs_trans_end(sdp);
> ogfs_gunlock_rg(rgd, 0);
> ogfs_rgrpd_put(rgd);
> }
>
> ogfs_rindex_release(sdp);
> return error;
>
> }
Index: src/fs/blklist.h
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/blklist.h,v
retrieving revision 1.7
diff -r1.7 blklist.h
64a65
> int ogfs_reclaim_freemeta(ogfs_sbd_t *sdp, void *arg);
Index: src/fs/ioctl.c
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/ioctl.c,v
retrieving revision 1.17
diff -r1.17 ioctl.c
24a25
> #include "blklist.h"
415a417,427
> }
>
> /**
> * ogfs_reclaim_freemeta_ioctl - ioctl function for reclaiming excess
> * free metadata block
> * @sdp: the filesystem
> * @arg:
> * */
> int ogfs_reclaim_freemeta_ioctl(ogfs_sbd_t *sdp, void *arg)
> {
> return ogfs_reclaim_freemeta(sdp, arg);
Index: src/fs/ioctl.h
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/ioctl.h,v
retrieving revision 1.4
diff -r1.4 ioctl.h
28a29,30
> int ogfs_reclaim_freemeta_ioctl(ogfs_sbd_t * sdp, void *arg);
>
Index: src/fs/ogfs_ioctl.h
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/ogfs_ioctl.h,v
retrieving revision 1.3
diff -r1.3 ogfs_ioctl.h
35a36,37
> #define OGFS_RECLAIM_FREEMETA _GFSC_(13)
>
Index: src/fs/arch_linux_2_4/file.c
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/fs/arch_linux_2_4/file.c,v
retrieving revision 1.17
diff -r1.17 file.c
883a884,889
> case OGFS_RECLAIM_FREEMETA:
> lock_kernel();
> error = ogfs_reclaim_freemeta_ioctl(sdp, (void *) arg);
> unlock_kernel();
> break;
>
Index: src/tools/ogfs_tool/main.c
===================================================================
RCS file: /cvsroot/opengfs/opengfs/src/tools/ogfs_tool/main.c,v
retrieving revision 1.8
diff -r1.8 main.c
69a70,72
> "Reclaim the excess free metadata blocks:\n",
> " ogfs_tool reclaim <filename>\n",
> "\n",
275a279,313
> /*
> *
> * void reclaim()
> *
> * Description:
> * This routine uses an ioctl command to ask OGFS reclaim the excess free
> * metadata blocks.
> *
> * Input(s):
> * argc -
> * **argv -
> *
> */
>
> void reclaim(int argc, char **argv)
> {
> int fd;
>
>
> if (argc != 3)
> die("not enough arguments\n");
>
>
> fd = open(argv[2], O_RDONLY);
> if (fd < 0)
> die("can't open %s: %s\n", argv[2], strerror(errno));
>
>
> if (ioctl(fd, OGFS_RECLAIM_FREEMETA, NULL) < 0)
> die("error doing ioctl: %s\n", strerror(errno));
>
>
> close(fd);
> }
>
306a345,346
> } else if (strcmp(argv[1], "reclaim") == 0) {
> reclaim(argc, argv);
[Kernel]
[Security]
[Bugtraq]
[Photo]
[Yosemite]
[MIPS Linux]
[ARM Linux]
[Linux Clusters]
[Linux RAID]
[Yosemite Hiking]
[Linux Resources]