hammer2 - Add bulkfree directive.
authorMatthew Dillon <dillon@apollo.backplane.com>
Tue, 27 Jan 2015 02:04:30 +0000 (18:04 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 27 Jan 2015 02:04:30 +0000 (18:04 -0800)
* Add a bulkfree directive for testing the bulkfree code.

sbin/hammer2/Makefile
sbin/hammer2/cmd_bulkfree.c [new file with mode: 0644]
sbin/hammer2/cmd_debug.c
sbin/hammer2/hammer2.h
sbin/hammer2/main.c

index 616602d..c30d56a 100644 (file)
@@ -3,6 +3,7 @@ SRCS=   main.c subs.c icrc.c
 SRCS+= cmd_remote.c cmd_snapshot.c cmd_pfs.c
 SRCS+= cmd_service.c cmd_leaf.c cmd_debug.c
 SRCS+= cmd_rsa.c cmd_stat.c cmd_setcomp.c cmd_setcheck.c
+SRCS+= cmd_bulkfree.c
 SRCS+= print_inode.c
 #MAN=  hammer2.8
 NOMAN= TRUE
diff --git a/sbin/hammer2/cmd_bulkfree.c b/sbin/hammer2/cmd_bulkfree.c
new file mode 100644 (file)
index 0000000..dc27394
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015 The DragonFly Project.  All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Matthew Dillon <dillon@dragonflybsd.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "hammer2.h"
+
+int
+cmd_bulkfree(const char *sel_path)
+{
+       hammer2_ioc_bulkfree_t bfi;
+       int ecode;
+       int fd;
+       int res;
+
+       bzero(&bfi, sizeof(bfi));
+       bfi.size = 8192 * 1024;
+
+       if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
+               return 1;
+       res = ioctl(fd, HAMMER2IOC_BULKFREE_SCAN, &bfi);
+       if (res) {
+               perror("ioctl");
+               ecode = 1;
+       }
+       ecode = 0;
+       return ecode;
+}
index c9100da..67b4e72 100644 (file)
@@ -670,7 +670,7 @@ show_bref(int fd, int tab, int bi, hammer2_blockref_t *bref, int dofreemap)
                            media.bmdata[i].avail == 0) {
                                continue;
                        }
-                       tabprintf(tab + 4, "%04d.%04x (avail=%5d) "
+                       tabprintf(tab + 4, "%04d.%04x (avail=%7d) "
                                  "%08x %08x %08x %08x %08x %08x %08x %08x\n",
                                  i, media.bmdata[i].class,
                                  media.bmdata[i].avail,
index cfb62a3..bc92042 100644 (file)
@@ -142,6 +142,7 @@ int cmd_rsaenc(const char **keys, int nkeys);
 int cmd_rsadec(const char **keys, int nkeys);
 int cmd_setcomp(const char *comp_str, char **paths);
 int cmd_setcheck(const char *comp_str, char **paths);
+int cmd_bulkfree(const char *dir_path);
 
 /*
  * Misc functions
index 7da4fa4..eaace8b 100644 (file)
@@ -397,9 +397,17 @@ main(int ac, char **av)
                        fprintf(stderr,
                                "printinode: requires directory/file path\n");
                        usage(1);
-               }
-               else
+               } else {
                        print_inode(av[1]);
+               }
+       } else if (strcmp(av[0], "bulkfree") == 0) {
+               if (ac != 2) {
+                       fprintf(stderr,
+                               "bulkfree: requires path to mount\n");
+                       usage(1);
+               } else {
+                       ecode = cmd_bulkfree(av[1]);
+               }
        } else {
                fprintf(stderr, "Unrecognized command: %s\n", av[0]);
                usage(1);
@@ -474,6 +482,8 @@ usage(int code)
                        "Set check algo to crc64\n"
                "    setsha192 path...            "
                        "Set check algo to sha192\n"
+               "    bulkfree path...             "
+                       "Run bulkfree pass\n"
        );
        exit(code);
 }