Do not stop scanning on a cache-device link is missing since

it might not exists when a cache disk device is removed and
further cache device might be active.

Also handle the case where cache set might not be registered
and the status should just believe what the super block
says and not mark the disk as missing.

This part of code needs optimization but that is a separate
change.

    Issue DAT-1859
    Issue DAT-1860

Change-Id: I7eb8e8ff517eae240fde30c70b3ac90aa9a50ed6
This commit is contained in:
Raghu Krishnamurthy 2015-01-28 21:53:55 -08:00
parent 38aa84d04b
commit b0ed54d843

View File

@ -613,7 +613,7 @@ int bcache_query_devs(NihCommand *command, char *const *args)
int bcache_status(NihCommand *command, char *const *args) int bcache_status(NihCommand *command, char *const *args)
{ {
int i, dev_count = 0, seq; int i, dev_count = 0, seq, cache_count = 0;
struct cache_sb *seq_sb = NULL; struct cache_sb *seq_sb = NULL;
char cache_path[MAX_PATH]; char cache_path[MAX_PATH];
char *dev_names[MAX_DEVS]; char *dev_names[MAX_DEVS];
@ -653,7 +653,7 @@ int bcache_status(NihCommand *command, char *const *args)
* Get a list of all the devices from sysfs first, then * Get a list of all the devices from sysfs first, then
* compare it to the list we get back from the most up * compare it to the list we get back from the most up
* to date superblock. If there are any devices in the superblock * to date superblock. If there are any devices in the superblock
* that are not in sysfs, print out 'NOT PRESENT' * that are not in sysfs, print out 'missing'
*/ */
while (true) { while (true) {
char buf[MAX_PATH]; char buf[MAX_PATH];
@ -661,9 +661,12 @@ int bcache_status(NihCommand *command, char *const *args)
DIR *cache_dir; DIR *cache_dir;
if(((cache_dir = opendir(cache_path)) == NULL) && if(((cache_dir = opendir(cache_path)) == NULL) &&
dev_count < MAX_DEVS) cache_count > MAX_DEVS)
break; break;
if (cache_dir)
closedir(cache_dir);
if((len = readlink(cache_path, buf, sizeof(buf) - 1)) != -1) { if((len = readlink(cache_path, buf, sizeof(buf) - 1)) != -1) {
struct cache_sb *sb; struct cache_sb *sb;
char dev_uuid[40]; char dev_uuid[40];
@ -682,15 +685,13 @@ int bcache_status(NihCommand *command, char *const *args)
free(sb); free(sb);
dev_uuids[dev_count] = strdup(dev_uuid); dev_uuids[dev_count] = strdup(dev_uuid);
} else { dev_count++;
dev_uuids[dev_count] = strdup("Nothing");
dev_names[dev_count] = strdup("Nothing");
} }
cache_path[strlen(cache_path) - strlen(intbuf)] = 0; cache_path[strlen(cache_path) - strlen(intbuf)] = 0;
dev_count++; cache_count++;
snprintf(intbuf, 4, "%d", dev_count); snprintf(intbuf, 4, "%d", cache_count);
strcat(cache_path, intbuf); strcat(cache_path, intbuf);
} }
@ -701,18 +702,15 @@ int bcache_status(NihCommand *command, char *const *args)
int j; int j;
uuid_unparse(m->uuid.b, uuid_str); uuid_unparse(m->uuid.b, uuid_str);
snprintf(dev_state, MAX_PATH, "%s",
cache_state[CACHE_STATE(m)]);
for (j = 0; j < dev_count; j++) { for (j = 0; j < dev_count; j++) {
if (!strcmp(uuid_str, dev_uuids[j])) { if (!strcmp(uuid_str, dev_uuids[j])) {
snprintf(dev_state, MAX_PATH, "%s",
cache_state[CACHE_STATE(m)]);
break; break;
} else if (j == dev_count - 1) { } else if (j == dev_count - 1) {
if (!strcmp(cache_state[CACHE_STATE(m)], "active")) if (!strcmp(cache_state[CACHE_STATE(m)], "active"))
snprintf(dev_state, MAX_PATH, "%s", "missing"); snprintf(dev_state, MAX_PATH, "%s", "missing");
else
snprintf(dev_state, MAX_PATH, "%s",
cache_state[CACHE_STATE(m)]);
break; break;
} }
} }