diff --git a/lib/libhammer/info.c b/lib/libhammer/info.c index 856c31a..8ecb115 100644 --- a/lib/libhammer/info.c +++ b/lib/libhammer/info.c @@ -95,12 +95,6 @@ libhammer_get_volinfo(const char *path) pfstmp->ismaster = (pfs_od->mirror_flags & HAMMER_PFSD_SLAVE) ? 0 : 1; - if (pi.pos == 0) - pfstmp->mountedon = strdup(path); - else - pfstmp->mountedon = - libhammer_find_pfs_mount(pi.pos, - hvi->vol_fsid, pfstmp->ismaster); /* * Fill in structs used in the library. We don't rely on * HAMMER own struct but we do fill our own. @@ -110,6 +104,8 @@ libhammer_get_volinfo(const char *path) pfstmp->mirror_flags = pfs_od->mirror_flags; pfstmp->beg_tid = pfs_od->sync_beg_tid; pfstmp->end_tid = pfs_od->sync_end_tid; + pfstmp->mountedon = + libhammer_find_pfs_mount(&pfs_od->unique_uuid); pfstmp->snapcount = count_snapshots(hvi->version, pfstmp->snapshots, pfstmp->mountedon, &pfstmp->head.error); diff --git a/lib/libhammer/libhammer.h b/lib/libhammer/libhammer.h index 712abc0..e15cc51 100644 --- a/lib/libhammer/libhammer.h +++ b/lib/libhammer/libhammer.h @@ -166,7 +166,7 @@ int libhammer_stats_btree_searches(int64_t *); int libhammer_btree_stats(struct libhammer_btree_stats *); int libhammer_io_stats(struct libhammer_io_stats *); -char *libhammer_find_pfs_mount(int, uuid_t, int); +char *libhammer_find_pfs_mount(uuid_t *); void *_libhammer_malloc(size_t); __END_DECLS diff --git a/lib/libhammer/misc.c b/lib/libhammer/misc.c index 194e81b..f7d8056 100644 --- a/lib/libhammer/misc.c +++ b/lib/libhammer/misc.c @@ -46,15 +46,16 @@ #include "libhammer.h" char * -libhammer_find_pfs_mount(int pfsid, uuid_t parentuuid, int ismaster) +libhammer_find_pfs_mount(uuid_t *unique_uuid) { - struct hammer_ioc_info hi; + struct hammer_ioc_pseudofs_rw pfs; + struct hammer_pseudofs_data pfsd; struct statfs *mntbuf; int mntsize; int curmount; int fd; size_t mntbufsize; - char *trailstr; + uuid_t uuid; char *retval; retval = NULL; @@ -70,8 +71,6 @@ libhammer_find_pfs_mount(int pfsid, uuid_t parentuuid, int ismaster) mntsize = getfsstat(mntbuf, (long)mntbufsize, MNT_NOWAIT); curmount = mntsize - 1; - asprintf(&trailstr, ":%05d", pfsid); - /* * Iterate all the mounted points looking for the PFS passed to * this function. @@ -79,42 +78,41 @@ libhammer_find_pfs_mount(int pfsid, uuid_t parentuuid, int ismaster) while(curmount >= 0) { struct statfs *mnt = &mntbuf[curmount]; /* - * We need to avoid that PFS belonging to other HAMMER - * filesystems are showed as mounted, so we compare - * against the FSID, which is presumable to be unique. + * Discard any non null(5) or hammer(5) filesystems as synthetic + * filesystems like procfs(5) could accept ioctl calls and thus + * produce bogus results. */ - bzero(&hi, sizeof(hi)); - if ((fd = open(mnt->f_mntfromname, O_RDONLY)) < 0) { + if ((strcmp("hammer", mnt->f_fstypename) != 0) && + (strcmp("null", mnt->f_fstypename) != 0)) { + curmount--; + continue; + } + if ((fd = open(mnt->f_mntonname, O_RDONLY)) < 0) { curmount--; continue; } - if (ioctl(fd, HAMMERIOC_GET_INFO, &hi) < 0) { + bzero(&pfs, sizeof(pfs)); + bzero(&pfsd, sizeof(pfsd)); + pfs.pfs_id = -1; + pfs.ondisk = &pfsd; + pfs.bytes = sizeof(struct hammer_pseudofs_data); + if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) < 0) { + perror("ioctl"); close(fd); curmount--; continue; } - if (strstr(mnt->f_mntfromname, trailstr) != NULL && - (uuid_compare(&hi.vol_fsid, &parentuuid, NULL)) == 0) { - if (ismaster) { - if (strstr(mnt->f_mntfromname, - "@@-1") != NULL) { - retval = strdup(mnt->f_mntonname); - break; - } - } else { - if (strstr(mnt->f_mntfromname, - "@@0x") != NULL ) { - retval = strdup(mnt->f_mntonname); - break; - } - } + memcpy(&uuid, &pfs.ondisk->unique_uuid, sizeof(uuid)); + if (uuid_compare(unique_uuid, &uuid, NULL) == 0) { + retval = strdup(mnt->f_mntonname); + break; } + curmount--; close(fd); } - free(trailstr); free(mntbuf); return retval; diff --git a/sbin/hammer/cmd_snapshot.c b/sbin/hammer/cmd_snapshot.c index 2703684..152514a 100644 --- a/sbin/hammer/cmd_snapshot.c +++ b/sbin/hammer/cmd_snapshot.c @@ -494,7 +494,7 @@ snapshot_ls(const char *path) struct tm *tp; time_t t; u_int32_t i; - int fd, ismaster; + int fd; char snapts[64]; char *mntpoint; @@ -520,8 +520,7 @@ snapshot_ls(const char *path) /* not reached */ } - ismaster = (pfs_od.mirror_flags & HAMMER_PFSD_SLAVE) ? 0 : 1; - mntpoint = libhammer_find_pfs_mount(pfs.pfs_id, info.vol_fsid, ismaster); + mntpoint = libhammer_find_pfs_mount(&pfs.ondisk->unique_uuid); /* Note the degenerate case of PFS #0 */ printf("Snapshots on %s\tPFS #%d\n",