]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: make sure we have a device before trying to unmap
authorJosh Durgin <josh.durgin@inktank.com>
Mon, 24 Sep 2012 21:49:27 +0000 (14:49 -0700)
committerSamuel Just <sam.just@inktank.com>
Tue, 25 Sep 2012 21:09:27 +0000 (14:09 -0700)
CID 717444: Explicit null dereferenced (FORWARD_NULL)
 At (48): Passing null pointer "devpath" to function
"do_kernel_rm(char const *)", which dereferences it.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
src/rbd.cc
src/test/cli/rbd/bad-map.t [new file with mode: 0644]

index 478b15e46a95679b75ae9dca95b6c202095083f1..5d1615581837a5f0a5315564f9b073120aa18492 100644 (file)
@@ -1375,6 +1375,12 @@ int main(int argc, const char **argv)
     return EXIT_FAILURE;
   }
 
+  if (opt_cmd == OPT_UNMAP && !devpath) {
+    cerr << "error: device path was not specified" << std::endl;
+    usage();
+    return EXIT_FAILURE;
+  }
+
   // do this unconditionally so we can parse pool/image@snapshot into
   // the relevant parts
   set_pool_image_name(poolname, imgname, (char **)&poolname,
diff --git a/src/test/cli/rbd/bad-map.t b/src/test/cli/rbd/bad-map.t
new file mode 100644 (file)
index 0000000..590441e
--- /dev/null
@@ -0,0 +1,120 @@
+  $ rbd map
+  error: image name was not specified
+  usage: rbd [-n <auth user>] [OPTIONS] <cmd> ...
+  where 'pool' is a rados pool name (default is 'rbd') and 'cmd' is one of:
+    (ls | list) [pool-name]                     list rbd images
+    info <image-name>                           show information about image size,
+                                                striping, etc.
+    create [--order <bits>] --size <MB> <name>  create an empty image
+    clone [--order <bits>] <parentsnap> <clonename>
+                                                clone a snapshot into a COW
+                                                child image
+    children <snap-name>                        display children of snapshot
+    flatten <image-name>                        fill clone with parent data
+                                                (make it independent)
+    resize --size <MB> <image-name>             resize (expand or contract) image
+    rm <image-name>                             delete an image
+    export <image-name> <path>                  export image to file
+    import <path> <image-name>                  import image from file
+                                                (dest defaults)
+                                                as the filename part of file)
+    (cp | copy) <src> <dest>                    copy src image to dest
+    (mv | rename) <src> <dest>                  rename src image to dest
+    snap ls <image-name>                        dump list of image snapshots
+    snap create <snap-name>                     create a snapshot
+    snap rollback <snap-name>                   rollback image to snapshot
+    snap rm <snap-name>                         deletes a snapshot
+    snap purge <image-name>                     deletes all snapshots
+    snap protect <snap-name>                    prevent a snapshot from being deleted
+    snap unprotect <snap-name>                  allow a snapshot to be deleted
+    watch <image-name>                          watch events on image
+    map <image-name>                            map image to a block device
+                                                using the kernel
+    unmap <device>                              unmap a rbd device that was
+                                                mapped by the kernel
+    showmapped                                  show the rbd images mapped
+                                                by the kernel
+    lock list <image-name>                      show locks held on an image
+    lock add <image-name> <id> [--shared <tag>] take a lock called id on an image
+    lock remove <image-name> <id> <locker>      release a lock on an image
+  
+  <image-name>, <snap-name> are [pool/]name[@snap], or you may specify
+  individual pieces of names with -p/--pool, --image, and/or --snap.
+  
+  Other input options:
+    -p, --pool <pool>            source pool name
+    --image <image-name>         image name
+    --dest <image-name>          destination [pool and] image name
+    --snap <snap-name>           snapshot name
+    --dest-pool <name>           destination pool name
+    --path <path-name>           path name for import/export
+    --size <size in MB>          size of image for create and resize
+    --order <bits>               the object size in bits; object size will be
+                                 (1 << order) bytes. Default is 22 (4 MB).
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
+    --id <username>              rados user (without 'client.' prefix) to authenticate as
+    --keyfile <path>             file containing secret key for use with cephx
+    --shared <tag>               take a shared (rather than exclusive) lock
+  [1]
+  $ rbd unmap
+  error: device path was not specified
+  usage: rbd [-n <auth user>] [OPTIONS] <cmd> ...
+  where 'pool' is a rados pool name (default is 'rbd') and 'cmd' is one of:
+    (ls | list) [pool-name]                     list rbd images
+    info <image-name>                           show information about image size,
+                                                striping, etc.
+    create [--order <bits>] --size <MB> <name>  create an empty image
+    clone [--order <bits>] <parentsnap> <clonename>
+                                                clone a snapshot into a COW
+                                                child image
+    children <snap-name>                        display children of snapshot
+    flatten <image-name>                        fill clone with parent data
+                                                (make it independent)
+    resize --size <MB> <image-name>             resize (expand or contract) image
+    rm <image-name>                             delete an image
+    export <image-name> <path>                  export image to file
+    import <path> <image-name>                  import image from file
+                                                (dest defaults)
+                                                as the filename part of file)
+    (cp | copy) <src> <dest>                    copy src image to dest
+    (mv | rename) <src> <dest>                  rename src image to dest
+    snap ls <image-name>                        dump list of image snapshots
+    snap create <snap-name>                     create a snapshot
+    snap rollback <snap-name>                   rollback image to snapshot
+    snap rm <snap-name>                         deletes a snapshot
+    snap purge <image-name>                     deletes all snapshots
+    snap protect <snap-name>                    prevent a snapshot from being deleted
+    snap unprotect <snap-name>                  allow a snapshot to be deleted
+    watch <image-name>                          watch events on image
+    map <image-name>                            map image to a block device
+                                                using the kernel
+    unmap <device>                              unmap a rbd device that was
+                                                mapped by the kernel
+    showmapped                                  show the rbd images mapped
+                                                by the kernel
+    lock list <image-name>                      show locks held on an image
+    lock add <image-name> <id> [--shared <tag>] take a lock called id on an image
+    lock remove <image-name> <id> <locker>      release a lock on an image
+  
+  <image-name>, <snap-name> are [pool/]name[@snap], or you may specify
+  individual pieces of names with -p/--pool, --image, and/or --snap.
+  
+  Other input options:
+    -p, --pool <pool>            source pool name
+    --image <image-name>         image name
+    --dest <image-name>          destination [pool and] image name
+    --snap <snap-name>           snapshot name
+    --dest-pool <name>           destination pool name
+    --path <path-name>           path name for import/export
+    --size <size in MB>          size of image for create and resize
+    --order <bits>               the object size in bits; object size will be
+                                 (1 << order) bytes. Default is 22 (4 MB).
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
+    --id <username>              rados user (without 'client.' prefix) to authenticate as
+    --keyfile <path>             file containing secret key for use with cephx
+    --shared <tag>               take a shared (rather than exclusive) lock
+  [1]