dm cache: return -EINVAL if the user specifies unknown cache policy
authorMikulas Patocka <mpatocka@redhat.com>
Tue, 1 Oct 2013 22:35:39 +0000 (18:35 -0400)
committerMike Snitzer <snitzer@redhat.com>
Sat, 9 Nov 2013 23:20:18 +0000 (18:20 -0500)
Return -EINVAL when the specified cache policy is unknown rather than
returning -ENOMEM.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-cache-policy.c
drivers/md/dm-cache-target.c

index 21c03c570c06b7d2bac4bf1abc1d41147d7cd168..d80057968407ee550627d08bb5d76399df798d78 100644 (file)
@@ -119,13 +119,13 @@ struct dm_cache_policy *dm_cache_policy_create(const char *name,
        type = get_policy(name);
        if (!type) {
                DMWARN("unknown policy type");
-               return NULL;
+               return ERR_PTR(-EINVAL);
        }
 
        p = type->create(cache_size, origin_size, cache_block_size);
        if (!p) {
                put_policy(type);
-               return NULL;
+               return ERR_PTR(-ENOMEM);
        }
        p->private = type;
 
index 50afdf72285beb61ab4609083711bfbc1f5dfdef..81fe85757585a34187a8cd6059e283e527fa1df1 100644 (file)
@@ -1879,14 +1879,15 @@ static int set_config_values(struct cache *cache, int argc, const char **argv)
 static int create_cache_policy(struct cache *cache, struct cache_args *ca,
                               char **error)
 {
-       cache->policy = dm_cache_policy_create(ca->policy_name,
-                                              cache->cache_size,
-                                              cache->origin_sectors,
-                                              cache->sectors_per_block);
-       if (!cache->policy) {
+       struct dm_cache_policy *p = dm_cache_policy_create(ca->policy_name,
+                                                          cache->cache_size,
+                                                          cache->origin_sectors,
+                                                          cache->sectors_per_block);
+       if (IS_ERR(p)) {
                *error = "Error creating cache's policy";
-               return -ENOMEM;
+               return PTR_ERR(p);
        }
+       cache->policy = p;
 
        return 0;
 }