Refactor command validation
authorJens Axboe <jaxboe@fusionio.com>
Fri, 8 Oct 2010 17:58:11 +0000 (19:58 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Fri, 8 Oct 2010 17:58:11 +0000 (19:58 +0200)
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
main.c

diff --git a/main.c b/main.c
index 45da4f6e9cc903fb510ebc6374c7c1b276a38392..3d9144c6b87d34483c6c33559f01a6d5d9919e88 100644 (file)
--- a/main.c
+++ b/main.c
@@ -290,23 +290,23 @@ static void b_dev_complete_commands(struct b_dev *bd)
 
 static int b_dev_validate_command(struct b_user_cmd *buc)
 {
+       int i;
+
        if (!binject_buc_check_magic(buc))
                return -EINVAL;
 
-       switch (buc->type) {
-       case B_TYPE_WRITE:
-       case B_TYPE_READ:
-       case B_TYPE_DISCARD:
-       case B_TYPE_READVOID:
-       case B_TYPE_WRITEZERO:
-       case B_TYPE_READBARRIER:
-       case B_TYPE_WRITEBARRIER:
-               if (buc->len)
-                       return 0;
-               return -EINVAL;
-       default:
-               return -EINVAL;
+       for (i = 0; i < B_TYPE_NR; i++) {
+               const struct uc_map *ucm = &uc_map[i];
+
+               if (ucm->type != buc->type)
+                       continue;
+               if (ucm->data_transfer && !buc->len)
+                       break;
+
+               return 0;
        }
+
+       return -EINVAL;
 }
 
 static void b_cmd_endio(struct bio *bio, int error)