sysfs_get_str() usages have inconsistant buffer size.
This results in wild buffer declarations and redundant memory usage.
Define maximum buffer size for sysfs strings.
Replace wild sysfs string buffer sizes for globaly defined value.
Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
char *subarray = NULL;
int ret = 0;
char container_dev[PATH_MAX];
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (s->consistency_policy != CONSISTENCY_POLICY_RESYNC &&
s->consistency_policy != CONSISTENCY_POLICY_PPL) {
}
if (s->consistency_policy == CONSISTENCY_POLICY_PPL) {
- if (sysfs_get_str(sra, NULL, "sync_action", buf, 20) <= 0) {
+ if (sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) <= 0) {
ret = 1;
goto free_info;
} else if (strcmp(buf, "reshape\n") == 0) {
else {
struct mdinfo *sra = sysfs_read(-1, st->devnm, GET_VERSION);
int err;
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (!sra)
return -1;
/* Need to clear any 'read-auto' status */
- if (sysfs_get_str(sra, NULL, "array_state", buf, 20) > 0 &&
+ if (sysfs_get_str(sra, NULL, "array_state", buf, sizeof(buf)) > 0 &&
strncmp(buf, "read-auto", 9) == 0)
sysfs_set_str(sra, NULL, "array_state", "clean");
return unfreeze_container(st);
else {
struct mdinfo *sra = sysfs_read(-1, st->devnm, GET_VERSION);
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (sra &&
- sysfs_get_str(sra, NULL, "sync_action", buf, 20) > 0 &&
+ sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) > 0 &&
strcmp(buf, "frozen\n") == 0)
sysfs_set_str(sra, NULL, "sync_action", "idle");
sysfs_free(sra);
static void wait_reshape(struct mdinfo *sra)
{
int fd = sysfs_get_fd(sra, NULL, "sync_action");
- char action[20];
+ char action[SYSFS_MAX_BUF_SIZE];
if (fd < 0)
return;
- while (sysfs_fd_get_str(fd, action, 20) > 0 &&
+ while (sysfs_fd_get_str(fd, action, sizeof(action)) > 0 &&
strncmp(action, "reshape", 7) == 0)
sysfs_wait(fd, NULL);
close(fd);
* to close a race with the array_state going clean before the
* next write to raid_disks / stripe_cache_size
*/
- char safe[50];
+ char safe[SYSFS_MAX_BUF_SIZE];
int rc;
/* only 'raid_disks' and 'stripe_cache_size' trigger md_allow_write */
static int verify_reshape_position(struct mdinfo *info, int level)
{
int ret_val = 0;
- char buf[40];
+ char buf[SYSFS_MAX_BUF_SIZE];
int rv;
/* read sync_max, failure can mean raid0 array */
- rv = sysfs_get_str(info, NULL, "sync_max", buf, 40);
+ rv = sysfs_get_str(info, NULL, "sync_max", buf, sizeof(buf));
if (rv > 0) {
char *ep;
unsigned long long array_size;
int done;
struct mdinfo *sra = NULL;
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
/* when reshaping a RAID0, the component_size might be zero.
* So try to fix that up.
unsigned long long array_size = (info->component_size
* reshape->before.data_disks);
int fd;
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
/* First, we unsuspend any region that is now known to be safe.
* If suspend_point is on the 'wrong' side of reshape_progress, then
/* Check that sync_action is still 'reshape' to avoid
* waiting forever on a dead array
*/
- char action[20];
- if (sysfs_get_str(info, NULL, "sync_action", action, 20) <= 0 ||
+ char action[SYSFS_MAX_BUF_SIZE];
+ if (sysfs_get_str(info, NULL, "sync_action", action, sizeof(action)) <= 0 ||
strncmp(action, "reshape", 7) != 0)
break;
/* Some kernels reset 'sync_completed' to zero
*/
if (completed == 0) {
unsigned long long reshapep;
- char action[20];
- if (sysfs_get_str(info, NULL, "sync_action", action, 20) > 0 &&
+ char action[SYSFS_MAX_BUF_SIZE];
+ if (sysfs_get_str(info, NULL, "sync_action", action, sizeof(action)) > 0 &&
strncmp(action, "idle", 4) == 0 &&
sysfs_get_ll(info, NULL,
"reshape_position", &reshapep) == 0)
if (sd->disk.state & (1<<MD_DISK_FAULTY))
continue;
if (sd->disk.state & (1<<MD_DISK_SYNC)) {
- char sbuf[100];
+ char sbuf[SYSFS_MAX_BUF_SIZE];
if (sysfs_get_str(sra, sd, "state",
sbuf, sizeof(sbuf)) < 0 ||
struct mdstat_ent *ent;
struct mddev_dev devlist;
struct mdinfo mdi;
- char buf[32];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (!id_path)
dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
char container[32];
int err;
int count;
- char buf[32];
+ char buf[SYSFS_MAX_BUF_SIZE];
unsigned long long rd1, rd2;
if (will_retry && verbose == 0)
if (mdi && is_level456(mdi->array.level) &&
sysfs_attribute_available(mdi, NULL, "sync_action") &&
sysfs_attribute_available(mdi, NULL, "reshape_direction") &&
- sysfs_get_str(mdi, NULL, "sync_action", buf, 20) > 0 &&
+ sysfs_get_str(mdi, NULL, "sync_action", buf, sizeof(buf)) > 0 &&
strcmp(buf, "reshape\n") == 0 &&
sysfs_get_two(mdi, NULL, "raid_disks", &rd1, &rd2) == 2) {
unsigned long long position, curr;
sprintf(dname, "dev-%s", dv->devname);
sysfd = sysfs_open(fd2devnm(fd), dname, "block/dev");
if (sysfd >= 0) {
- char dn[20];
- if (sysfs_fd_get_str(sysfd, dn, 20) > 0 &&
+ char dn[SYSFS_MAX_BUF_SIZE];
+ if (sysfs_fd_get_str(sysfd, dn, sizeof(dn)) > 0 &&
sscanf(dn, "%d:%d", &mj,&mn) == 2) {
rdev = makedev(mj,mn);
found = 1;
* sync_action does.
*/
struct mdinfo mdi;
- char buf[21];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (sysfs_init(&mdi, -1, devnm))
return 2;
if (sysfs_get_str(&mdi, NULL, "sync_action",
- buf, 20) > 0 &&
+ buf, sizeof(buf)) > 0 &&
strcmp(buf,"idle\n") != 0) {
e->percent = RESYNC_UNKNOWN;
if (strcmp(buf, "frozen\n") == 0) {
if (rv) {
int state_fd = sysfs_open(fd2devnm(fd), NULL, "array_state");
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
int delay = 5000;
/* minimize the safe_mode_delay and prepare to wait up to 5s
* trying to find and assign a spare.
* We do that whenever the monitor tells us too.
*/
- char buf[64];
+ char buf[SYSFS_MAX_BUF_SIZE];
int frozen;
struct supertype *container = a->container;
struct mdinfo *mdi;
struct mdinfo *mdi = NULL, *di;
int i, inst;
int failed = 0;
- char buf[40];
+ char buf[SYSFS_MAX_BUF_SIZE];
/* check if array is ready to be monitored */
if (!mdstat->active || !mdstat->level)
* read this information for new arrays only (empty victim)
*/
if ((victim == NULL) &&
- (sysfs_get_str(mdi, NULL, "sync_action", buf, 40) > 0) &&
+ (sysfs_get_str(mdi, NULL, "sync_action", buf, sizeof(buf)) > 0) &&
(strncmp(buf, "reshape", 7) == 0)) {
if (sysfs_get_ll(mdi, NULL, "reshape_position",
&new->last_checkpoint) != 0)
GET_DEVS_ALL = (1 << 27),
};
+#define SYSFS_MAX_BUF_SIZE 64
+
/* If fd >= 0, get the array it is open on,
* else use devnm.
*/
static void read_resync_start(int fd, unsigned long long *v)
{
- char buf[30];
+ char buf[SYSFS_MAX_BUF_SIZE];
int n;
- n = read_attr(buf, 30, fd);
+ n = read_attr(buf, sizeof(buf), fd);
if (n <= 0) {
dprintf("Failed to read resync_start (%d)\n", fd);
return;
static unsigned long long read_sync_completed(int fd)
{
unsigned long long val;
- char buf[50];
+ char buf[SYSFS_MAX_BUF_SIZE];
int n;
char *ep;
- n = read_attr(buf, 50, fd);
+ n = read_attr(buf, sizeof(buf), fd);
if (n <= 0)
return 0;
static enum array_state read_state(int fd)
{
- char buf[20];
- int n = read_attr(buf, 20, fd);
+ char buf[SYSFS_MAX_BUF_SIZE];
+ int n = read_attr(buf, sizeof(buf), fd);
if (n <= 0)
return bad_word;
static enum sync_action read_action( int fd)
{
- char buf[20];
- int n = read_attr(buf, 20, fd);
+ char buf[SYSFS_MAX_BUF_SIZE];
+ int n = read_attr(buf, sizeof(buf), fd);
if (n <= 0)
return bad_action;
int read_dev_state(int fd)
{
- char buf[100];
+ char buf[SYSFS_MAX_BUF_SIZE];
int n = read_attr(buf, sizeof(buf), fd);
char *cp;
int rv = 0;
*/
if ((a->curr_action != reshape) &&
(a->prev_action == reshape)) {
- char buf[40];
+ char buf[SYSFS_MAX_BUF_SIZE];
if ((sysfs_get_str(&a->info, NULL,
"reshape_position",
buf,
{
struct mdstat_ent *ent, *e, *e2;
struct mdinfo *sra = NULL;
- char buf[64];
+ char buf[SYSFS_MAX_BUF_SIZE];
int rv = 0;
if (check_mdmon_version(container))
!sysfs_attribute_available(sra, NULL, "sync_action")) ||
(freeze &&
sysfs_attribute_available(sra, NULL, "sync_action") &&
- sysfs_get_str(sra, NULL, "sync_action", buf, 20) > 0 &&
+ sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) > 0 &&
strcmp(buf, "frozen\n") == 0))
/* pass */;
else {
unsigned int sector_size = super->sector_size;
unsigned long long curr_migr_unit = current_migr_unit(migr_rec);
unsigned long long num_migr_units = get_num_migr_units(migr_rec);
- char buffer[20];
+ char buffer[SYSFS_MAX_BUF_SIZE];
int skipped_disks = 0;
struct dl *dl_disk;
- err = sysfs_get_str(info, NULL, "array_state", (char *)buffer, 20);
+ err = sysfs_get_str(info, NULL, "array_state", (char *)buffer, sizeof(buffer));
if (err < 1)
return 1;
static int read_completed(int fd, unsigned long long *val)
{
int ret;
- char buf[50];
+ char buf[SYSFS_MAX_BUF_SIZE];
- ret = sysfs_fd_get_str(fd, buf, 50);
+ ret = sysfs_fd_get_str(fd, buf, sizeof(buf));
if (ret < 0)
return ret;
do {
int rc;
- char action[20];
+ char action[SYSFS_MAX_BUF_SIZE];
int timeout = 3000;
sysfs_wait(fd, &timeout);
if (sysfs_get_str(sra, NULL, "sync_action",
- action, 20) > 0 &&
+ action, sizeof(action)) > 0 &&
strncmp(action, "reshape", 7) != 0) {
if (strncmp(action, "idle", 4) == 0)
break;
if (sd->disk.state & (1<<MD_DISK_FAULTY))
continue;
if (sd->disk.state & (1<<MD_DISK_SYNC)) {
- char sbuf[100];
+ char sbuf[SYSFS_MAX_BUF_SIZE];
int raid_disk = sd->disk.raid_disk;
if (sysfs_get_str(info,
ver[0] = 0;
if (info->array.major_version == -1 &&
info->array.minor_version == -2) {
- char buf[1024];
+ char buf[SYSFS_MAX_BUF_SIZE];
strcat(strcpy(ver, "external:"), info->text_version);
* version first, and preserve the flag
*/
if (sysfs_get_str(info, NULL, "metadata_version",
- buf, 1024) > 0)
+ buf, sizeof(buf)) > 0)
if (strlen(buf) >= 9 && buf[9] == '-')
ver[9] = '-';
* return 0 if this kernel doesn't support 'frozen'
* return 1 if it worked.
*/
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (!sysfs_attribute_available(sra, NULL, "sync_action"))
return 1; /* no sync_action == frozen */
- if (sysfs_get_str(sra, NULL, "sync_action", buf, 20) <= 0)
+ if (sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) <= 0)
return 0;
if (strcmp(buf, "frozen\n") == 0)
/* Already frozen */