mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-10 00:00:04 +03:00
bcacheadm: fix list-cachesets --list-devs
list-cachesets now searches through all cache# symlinks instead of iterating with i++. This is because bcache doesn't immediately reuse a cache# symlink when a dev gets removed. Fixes DAT-1635 Progress DAT-1646 Change-Id: I6901e29dc13f4e2a76bdc49871e87f07667ec786 Signed-off-by: Jacob Malevich <jam@daterainc.com>
This commit is contained in:
parent
62345dac62
commit
34f6746c33
39
bcache.c
39
bcache.c
@ -964,26 +964,40 @@ static char *dev_name(const char *ugly_path) {
|
|||||||
|
|
||||||
static void list_cacheset_devs(char *cset_dir, char *cset_name, bool parse_dev_name) {
|
static void list_cacheset_devs(char *cset_dir, char *cset_name, bool parse_dev_name) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
DIR *cachedir;
|
DIR *cachedir, *dir;
|
||||||
struct stat cache_stat;
|
struct stat cache_stat;
|
||||||
char intbuf[4];
|
|
||||||
char entry[MAX_PATH];
|
char entry[MAX_PATH];
|
||||||
|
struct dirent *ent;
|
||||||
|
snprintf(entry, MAX_PATH, "%s/%s", cset_dir, cset_name);
|
||||||
|
|
||||||
snprintf(entry, MAX_PATH, "%s/%s/cache0", cset_dir, cset_name);
|
if((dir = opendir(entry)) != NULL) {
|
||||||
snprintf(intbuf, 4, "%d", i);
|
while((ent = readdir(dir)) != NULL) {
|
||||||
|
|
||||||
while(true) {
|
|
||||||
char buf[MAX_PATH];
|
char buf[MAX_PATH];
|
||||||
int len;
|
int len;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We are looking for all cache# directories
|
||||||
|
* do a strlen < 9 to skip over other entries
|
||||||
|
* that also start with "cache"
|
||||||
|
*/
|
||||||
|
if(strncmp(ent->d_name, "cache", 5) ||
|
||||||
|
!(strlen(ent->d_name) < 9))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
snprintf(entry, MAX_PATH, "%s/%s/%s",
|
||||||
|
cset_dir,
|
||||||
|
cset_name,
|
||||||
|
ent->d_name);
|
||||||
|
|
||||||
if((cachedir = opendir(entry)) == NULL)
|
if((cachedir = opendir(entry)) == NULL)
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
if(stat(entry, &cache_stat))
|
if(stat(entry, &cache_stat))
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
if((len = readlink(entry, buf, sizeof(buf) - 1)) != -1) {
|
if((len = readlink(entry, buf, sizeof(buf) - 1)) !=
|
||||||
|
-1) {
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
if(parse_dev_name) {
|
if(parse_dev_name) {
|
||||||
tmp = dev_name(buf);
|
tmp = dev_name(buf);
|
||||||
@ -993,12 +1007,7 @@ static void list_cacheset_devs(char *cset_dir, char *cset_name, bool parse_dev_n
|
|||||||
printf("\t%s\n", buf);
|
printf("\t%s\n", buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* remove i from end and append i++ */
|
|
||||||
entry[strlen(entry)-strlen(intbuf)] = 0;
|
|
||||||
i++;
|
|
||||||
snprintf(intbuf, 4, "%d", i);
|
|
||||||
strcat(entry, intbuf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user