Whamcloud - gitweb
LU-14893 lctl: check user for changelog_deregister 32/44432/3
authorEmoly Liu <emoly@whamcloud.com>
Fri, 30 Jul 2021 08:13:12 +0000 (16:13 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 10 Aug 2021 08:08:16 +0000 (08:08 +0000)
If no user is specified for "lctl changelog_deregister", usage
should be printed correctly.
Also, sanity.sh test_106e is modified to verify this fix.

Fixes: a15eb4f13224e ("LU-13055 mdd: per-user changelog names and mask")
Signed-off-by: Emoly Liu <emoly@whamcloud.com>
Change-Id: Ia7f1b18e82f6b4174b9435cd67aba5f591d43ce1
Reviewed-on: https://review.whamcloud.com/44432
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Mike Pershin <mpershin@whamcloud.com>
Reviewed-by: James Nunez <jnunez@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity.sh
lustre/utils/obd.c

index 12ba699..0158353 100755 (executable)
@@ -15542,11 +15542,21 @@ test_160e() {
        # Create a user
        changelog_register || error "changelog_register failed"
 
-       # Delete a future user (expect fail)
        local MDT0=$(facet_svc $SINGLEMDS)
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister "cl77"
-       local rc=$?
+       local rc
 
+       # No user (expect fail)
+       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister
+       rc=$?
+       if [ $rc -eq 0 ]; then
+               error "Should fail without user"
+       elif [ $rc -ne 4 ]; then
+               error "changelog_deregister failed with $rc, expect 4(CMD_HELP)"
+       fi
+
+       # Delete a future user (expect fail)
+       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister "cl77"
+       rc=$?
        if [ $rc -eq 0 ]; then
                error "Deleted non-existant user cl77"
        elif [ $rc -ne 2 ]; then
index 83f1707..186b6b9 100644 (file)
@@ -5650,7 +5650,6 @@ int jt_changelog_deregister(int argc, char **argv)
        if (cur_device < 0 || !device)
                return CMD_HELP;
 
-       optind = 1;
        while ((c = getopt_long(argc, argv, "hu:", long_opts, NULL)) != -1) {
                switch (c) {
                case 'u':
@@ -5670,7 +5669,7 @@ int jt_changelog_deregister(int argc, char **argv)
                }
        }
 
-       if (1 == optind) {
+       if (1 == optind && argc > 1) {
                /* first check if pure ID was passed */
                id = atoi(argv[optind]);
                /* nameless cl<ID> format or cl<ID>-... format, only ID matters */
@@ -5688,7 +5687,7 @@ int jt_changelog_deregister(int argc, char **argv)
                optind++;
        }
 
-       if (optind < argc)
+       if (optind < argc || argc == 1)
                return CMD_HELP;
 
        data.ioc_dev = cur_device;