1
0
mirror of https://github.com/gluster/gluster-block.git synced 2026-02-05 12:45:33 +01:00

gluster-block: align the target device size to sector size

This will align the target device size to GB_DEFAULT_SECTOR_SIZE

Tested-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Reviewed-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Reviewed-by: Pranith Kumar K <pkarampu@redhat.com>
Signed-off-by: Xiubo Li <xiubli@redhat.com>
This commit is contained in:
Xiubo Li
2018-06-29 04:28:50 -04:00
committed by Prasanna Kumar Kalever
parent c13b288042
commit e971593411
2 changed files with 24 additions and 14 deletions

View File

@@ -40,8 +40,6 @@
} \
} while(0)
# define GB_DEFAULT_SECTOR_SIZE 512
extern const char *argp_program_version;
typedef enum clioperations {
@@ -414,11 +412,6 @@ glusterBlockModify(int argcount, char **options, int json)
LOG("cli", GB_LOG_ERROR, "Modify failed while parsing size for block <%s/%s>",
volume, block);
goto out;
} else if (sparse_ret < GB_DEFAULT_SECTOR_SIZE) {
MSG("minimum acceptable block size is %d bytes\n", GB_DEFAULT_SECTOR_SIZE);
LOG("cli", GB_LOG_ERROR, "minimum acceptable block size is %d bytes <%s/%s>",
GB_DEFAULT_SECTOR_SIZE, volume, block);
goto out;
}
if ((argcount - optind) && !strcmp(options[optind], "force")) {
@@ -588,11 +581,6 @@ glusterBlockCreate(int argcount, char **options, int json)
LOG("cli", GB_LOG_ERROR, "failed while parsing size for block <%s/%s>",
cobj.volume, cobj.block_name);
goto out;
} else if (sparse_ret < GB_DEFAULT_SECTOR_SIZE) {
MSG("minimum acceptable block size is %d bytes\n", GB_DEFAULT_SECTOR_SIZE);
LOG("cli", GB_LOG_ERROR, "minimum acceptable block size is %d bytes <%s/%s>",
GB_DEFAULT_SECTOR_SIZE, cobj.volume, cobj.block_name);
goto out;
}
cobj.size = sparse_ret; /* size is unsigned long long */
}

View File

@@ -37,6 +37,13 @@ jsonResponseFormatParse(const char *opt)
}
# define GB_DEFAULT_SECTOR_SIZE 512
# define round_down(a, b) ({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
(_a - (_a % _b)); })
ssize_t
glusterBlockParseSize(const char *dom, char *value)
{
@@ -49,8 +56,8 @@ glusterBlockParseSize(const char *dom, char *value)
return -1;
sizef = strtod(value, &postfix);
if (sizef < 0) {
LOG(dom, GB_LOG_ERROR, "%s", "size cannot be negative number");
if (sizef <= 0) {
LOG(dom, GB_LOG_ERROR, "%s", "size cannot be negative number or zero");
return -1;
}
@@ -86,6 +93,21 @@ glusterBlockParseSize(const char *dom, char *value)
/* fall through */
case 'b':
case '\0':
if (sizef < GB_DEFAULT_SECTOR_SIZE) {
MSG("minimum acceptable block size is %d bytes\n", GB_DEFAULT_SECTOR_SIZE);
LOG(dom, GB_LOG_ERROR, "minimum acceptable block size is %d bytes",
GB_DEFAULT_SECTOR_SIZE);
return -1;
}
if (sizef % GB_DEFAULT_SECTOR_SIZE) {
MSG("The size %lld will align to sector size %d bytes\n",
sizef, GB_DEFAULT_SECTOR_SIZE);
LOG(dom, GB_LOG_ERROR,
"The target device size %lld is will align to the sector size %d",
sizef, GB_DEFAULT_SECTOR_SIZE);
sizef = round_down(sizef, GB_DEFAULT_SECTOR_SIZE);
}
break;
default:
goto fail;