diff --git a/sbin/hammer/cmd_info.c b/sbin/hammer/cmd_info.c index 23230ef..1c3aeb7 100644 --- a/sbin/hammer/cmd_info.c +++ b/sbin/hammer/cmd_info.c @@ -36,6 +36,7 @@ #include void show_info(char *path); +char *find_pfs_mount(int pfsid, int ismaster); double percent(int64_t value, int64_t total); void @@ -54,22 +55,26 @@ hammer_cmd_info(void) if ((strcmp(fstype, "hammer")) == 0) show_info(path); } - } - else + } else { fprintf(stdout, "No mounted filesystems found\n"); + } } void show_info(char *path) { - int64_t usedbigblocks, bytes; - struct hammer_ioc_info info; - char buf[6]; - int fd; - char *fsid, *fstype; + struct hammer_ioc_pseudofs_rw pfs; + struct hammer_pseudofs_data pfs_od; + int64_t usedbigblocks, bytes; + struct hammer_ioc_info info; + int fd, pfs_id, ismaster; + char *fsid, *fstype; + char *mountedon; + char buf[6]; - fsid = fstype = NULL; + fsid = fstype = mountedon = NULL; usedbigblocks = 0; + pfs_id = 1; /* Do not include PFS#0 */ bytes = 0; bzero(&info, sizeof(struct hammer_ioc_info)); @@ -129,6 +134,82 @@ void show_info(char *path) { bytes = ((info.freebigblocks - info.rsvbigblocks) << HAMMER_LARGEBLOCK_BITS); humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1), bytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B); fprintf(stdout, "\tFree space %6s\n\n", buf); + + /* Pseudo-filesystem information */ + fprintf(stdout, "PFS information\n"); + while(pfs_id < HAMMER_MAX_PFS) { + bzero(&pfs, sizeof(pfs)); + bzero(&pfs_od, sizeof(pfs_od)); + pfs.pfs_id = pfs_id; + pfs.ondisk = &pfs_od; + pfs.bytes = sizeof(pfs_od); + pfs.version = HAMMER_IOC_PSEUDOFS_VERSION; + if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) >= 0) { + + ismaster = (pfs_od.mirror_flags & HAMMER_PFSD_SLAVE) ? 0 : 1; + mountedon = find_pfs_mount(pfs_id, ismaster); + if (mountedon) + fprintf(stdout, "\tPFS %05d mounted on %s (%s)\n", + pfs_id, mountedon, (ismaster ? "MASTER" : "SLAVE")); + else + fprintf(stdout, "\tPFS %05d not mounted (%s)\n", pfs_id, (ismaster ? "MASTER" : "SLAVE")); + + } + pfs_id++; + } + + free(mountedon); +} + +char *find_pfs_mount(int pfsid, int ismaster) { + + struct statfs *mntbuf; + int mntsize, curmount; + size_t mntbufsize; + char *retval, *trailstr; + + retval = NULL; + + /* Do not continue if there are no mounted filesystems */ + mntsize = getfsstat(NULL, 0, MNT_NOWAIT); + if (mntsize <= 0) + return retval; + + mntbufsize = (mntsize) * sizeof(struct statfs); + mntbuf = malloc(mntbufsize); + if (mntbuf == NULL) { + perror("show_info"); + exit(EXIT_FAILURE); + } + + mntsize = getfsstat(mntbuf, (long)mntbufsize, MNT_NOWAIT); + curmount = mntsize; + + asprintf(&trailstr, ":%05d", pfsid); + + /* + * Iterate all the mounted points looking for the PFS passed to + * this function. It will look for @@-1 latest TID only + */ + while(curmount >= 0) { + if (strstr(mntbuf[curmount].f_mntfromname, trailstr) != NULL) { + if (ismaster) { + if (strstr(mntbuf[curmount].f_mntfromname, "@@-1") != NULL) { + retval = strdup(mntbuf[curmount].f_mntonname); + break; + } + } else { + if (strstr(mntbuf[curmount].f_mntfromname, "@@0x") != NULL ) { + retval = strdup(mntbuf[curmount].f_mntonname); + break; + } + } + } + curmount--; + } + + free(trailstr); + return retval; } double percent(int64_t value, int64_t total) {