diff --git a/kernel/mars_if.c b/kernel/mars_if.c index af7bd0d3..fdf34214 100644 --- a/kernel/mars_if.c +++ b/kernel/mars_if.c @@ -966,7 +966,7 @@ loff_t if_get_capacity(struct if_brick *brick) * e.g. when the size symlink indicates a logically smaller * device than physically. */ - if (brick->dev_size <= 0) { + if (brick->real_size <= 0 || brick->max_size != brick->old_max_size) { struct if_input *input = brick->inputs[0]; int status; @@ -976,8 +976,14 @@ loff_t if_get_capacity(struct if_brick *brick) return 0; } MARS_INF("determined default capacity: %lld bytes\n", brick->info.current_size); - brick->dev_size = brick->info.current_size; + + brick->real_size = brick->info.current_size; } + if (brick->max_size > 0 && brick->real_size > brick->max_size) + brick->dev_size = brick->max_size; + else + brick->dev_size = brick->real_size; + brick->old_max_size = brick->max_size; return brick->dev_size; } diff --git a/kernel/mars_if.h b/kernel/mars_if.h index 11a5a3fb..11d39409 100644 --- a/kernel/mars_if.h +++ b/kernel/mars_if.h @@ -105,6 +105,8 @@ struct if_output { struct if_brick { MARS_BRICK(if); // parameters + loff_t real_size; + loff_t max_size; loff_t dev_size; int max_plugged; int readahead; @@ -119,6 +121,7 @@ struct if_brick { // private struct semaphore switch_sem; struct say_channel *say_channel; + loff_t old_max_size; struct mars_info info; }; diff --git a/kernel/sy_old/mars_main.c b/kernel/sy_old/mars_main.c index f4120a69..f5bc2637 100644 --- a/kernel/sy_old/mars_main.c +++ b/kernel/sy_old/mars_main.c @@ -1078,19 +1078,8 @@ int _set_if_params(struct mars_brick *_brick, void *private) MARS_ERR("bad brick type\n"); return -EINVAL; } - if (!rot) { - MARS_ERR("too early\n"); - return -EINVAL; - } - if (rot->dev_size <= 0) { - MARS_ERR("dev_size = %lld\n", rot->dev_size); - return -EINVAL; - } - if (if_brick->dev_size > 0 && rot->dev_size < if_brick->dev_size) { - MARS_ERR("new dev size = %lld < old dev_size = %lld\n", rot->dev_size, if_brick->dev_size); - return -EINVAL; - } - if_brick->dev_size = rot->dev_size; + if (likely(rot)) + if_brick->max_size = rot->dev_size; if_brick->max_plugged = IF_MAX_PLUGGED; if_brick->readahead = IF_READAHEAD; if_brick->skip_sync = IF_SKIP_SYNC;