if: distinguish real and max size

This commit is contained in:
Thomas Schoebel-Theuer 2015-10-15 08:48:04 +02:00
parent b80caec463
commit fd85f0804d
3 changed files with 13 additions and 15 deletions

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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;