sbin/newfs_hammer: Add -C option from hammer(8)
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 14 Aug 2016 15:54:05 +0000 (00:54 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Mon, 15 Aug 2016 12:02:26 +0000 (21:02 +0900)
Just to support the same options given that these are both based
on the same volume/buffer structure.

sbin/hammer/cache.c
sbin/hammer/hammer.c
sbin/hammer/hammer.h
sbin/hammer/hammer_util.h
sbin/newfs_hammer/newfs_hammer.8
sbin/newfs_hammer/newfs_hammer.c

index 5101431..bb2180e 100644 (file)
@@ -41,6 +41,46 @@ static int CacheMax = 16 * 1024 * 1024;
 static int NCache;
 static TAILQ_HEAD(, cache_info) CacheList = TAILQ_HEAD_INITIALIZER(CacheList);
 
+int
+hammer_parse_cache_size(const char *arg)
+{
+       char *ptr;
+       int size = strtol(arg, &ptr, 0);
+
+       switch(*ptr) {
+       case 'm':
+       case 'M':
+               size *= 1024;
+               /* fall through */
+       case 'k':
+       case 'K':
+               size *= 1024;
+               ++ptr;
+               break;
+       case '\0':
+       case ':':
+               /* bytes if no suffix */
+               break;
+       default:
+               return(-1);
+       }
+
+       if (*ptr == ':') {
+               UseReadAhead = strtol(ptr + 1, NULL, 0);
+               UseReadBehind = -UseReadAhead;
+       }
+       if (size < 1024 * 1024)
+               size = 1024 * 1024;
+       if (UseReadAhead < 0)
+               return(-1);
+       if (UseReadAhead * HAMMER_BUFSIZE / size / 16) {
+               UseReadAhead = size / 16 / HAMMER_BUFSIZE;
+               UseReadBehind = -UseReadAhead;
+       }
+       hammer_cache_set(size);
+       return(0);
+}
+
 void
 hammer_cache_set(int bytes)
 {
index 0b069e4..cb06603 100644 (file)
@@ -68,7 +68,6 @@ main(int ac, char **av)
        char *restrictcmd = NULL;
        uint32_t status;
        int ch;
-       int cacheSize = 0;
 
        while ((ch = getopt(ac, av,
                            "b:c:de:hf:i:m:p:qrt:v2yABC:FR:S:T:X")) != -1) {
@@ -197,37 +196,8 @@ main(int ac, char **av)
                        BulkOpt = 1;
                        break;
                case 'C':
-                       cacheSize = strtol(optarg, &ptr, 0);
-                       switch(*ptr) {
-                       case 'm':
-                       case 'M':
-                               cacheSize *= 1024;
-                               /* fall through */
-                       case 'k':
-                       case 'K':
-                               cacheSize *= 1024;
-                               ++ptr;
-                               break;
-                       case '\0':
-                       case ':':
-                               /* bytes if no suffix */
-                               break;
-                       default:
+                       if (hammer_parse_cache_size(optarg) == -1)
                                usage(1);
-                       }
-                       if (*ptr == ':') {
-                               UseReadAhead = strtol(ptr + 1, NULL, 0);
-                               UseReadBehind = -UseReadAhead;
-                       }
-                       if (cacheSize < 1024 * 1024)
-                               cacheSize = 1024 * 1024;
-                       if (UseReadAhead < 0)
-                               usage(1);
-                       if (UseReadAhead * HAMMER_BUFSIZE / cacheSize / 16) {
-                               UseReadAhead = cacheSize / 16 / HAMMER_BUFSIZE;
-                               UseReadBehind = -UseReadAhead;
-                       }
-                       hammer_cache_set(cacheSize);
                        break;
                case 'F':
                        ForceOpt = 1;
index 11a9599..47ac425 100644 (file)
@@ -82,8 +82,6 @@ extern int DidInterrupt;
 extern int ForceOpt;
 extern int BulkOpt;
 extern int AllPFS;
-extern int UseReadBehind;
-extern int UseReadAhead;
 extern int AssertOnFailure;
 extern uint64_t BandwidthOpt;
 extern uint64_t SplitupOpt;
index cb67306..1e74b25 100644 (file)
@@ -137,6 +137,8 @@ struct zone_stat {
 
 extern uuid_t Hammer_FSType;
 extern uuid_t Hammer_FSId;
+extern int UseReadBehind;
+extern int UseReadAhead;
 extern int DebugOpt;
 extern struct volume_list VolList;
 
@@ -185,6 +187,7 @@ void flush_buffer(struct buffer_info *buf);
 int64_t init_boot_area_size(int64_t value, off_t avg_vol_size);
 int64_t init_mem_area_size(int64_t value, off_t avg_vol_size);
 
+int hammer_parse_cache_size(const char *arg);
 void hammer_cache_set(int bytes);
 void hammer_cache_add(struct cache_info *cache);
 void hammer_cache_del(struct cache_info *cache);
index ae52464..7ddb53c 100644 (file)
@@ -30,7 +30,7 @@
 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd December 31, 2015
+.Dd August 15, 2016
 .Dt NEWFS_HAMMER 8
 .Os
 .Sh NAME
@@ -43,6 +43,7 @@
 .Op Fl b Ar bootsize
 .Op Fl m Ar savesize
 .Op Fl u Ar undosize
+.Op Fl C Ar cachesize Ns Op Ns Cm \&: Ns Ar readahead
 .Op Fl V Ar version
 .Ar special ...
 .Sh DESCRIPTION
@@ -146,6 +147,9 @@ By default 0.1% of the root
 volume's size is used, with a reasonable minimum and a reasonable cap.
 The UNDO/REDO FIFO is used to sequence meta-data out to the media for
 instant crash recovery.
+.It Fl C Ar cachesize Ns Op Ns Cm \&: Ns Ar readahead
+Refer to the same option in
+.Xr hammer 8 .
 .It Fl V Ar version
 Specify the
 .Nm HAMMER
index d6182a8..aa46fd5 100644 (file)
@@ -87,7 +87,7 @@ main(int ac, char **av)
        /*
         * Parse arguments
         */
-       while ((ch = getopt(ac, av, "dfEL:b:m:u:V:")) != -1) {
+       while ((ch = getopt(ac, av, "dfEL:b:m:u:C:V:")) != -1) {
                switch(ch) {
                case 'd':
                        ++DebugOpt;
@@ -126,6 +126,10 @@ main(int ac, char **av)
                                        "which may lead to VFS panics.\n");
                        }
                        break;
+               case 'C':
+                       if (hammer_parse_cache_size(optarg) == -1)
+                               usage();
+                       break;
                case 'V':
                        HammerVersion = strtol(optarg, NULL, 0);
                        if (HammerVersion < HAMMER_VOL_VERSION_MIN ||
@@ -276,7 +280,7 @@ usage(void)
 {
        fprintf(stderr,
                "usage: newfs_hammer -L label [-Ef] [-b bootsize] [-m savesize] [-u undosize]\n"
-               "                    [-V version] special ...\n"
+               "                    [-C cachesize[:readahead]] [-V version] special ...\n"
        );
        exit(1);
 }