Re: [ping] dump -U by default
On Tue, May 12, 2015 at 2:00 AM, Manuel Giraud wrote: > Philip Guenther writes: > >> Can we suppress the device form if there's a matching DUID entry? > > Okay. The DUID/device dance is not that easy (at least for me). So here > is a new patch that should work. > > For your issue, I choose to convert dumpdates entries to DUID (when > possible) at read time so dump now has the following features/drawbacks: > > - All dumpdates entries (of present devices) will be converted > to DUID at the next dump (even those that are not being dumped). > - Even a dump -w/W tries to opendev the device (in order to find > its UID). Semantics were good, thanks! There were a few resource leaks I took care of before committing: > +char * > +getduid(char *path) > +{ > + int fd; > + struct disklabel lab; > + u_int64_t zero_uid = 0; > + char *duid; > + > + if ((fd = opendev(path, O_RDONLY | O_NOFOLLOW, 0, NULL)) >= 0) { > + if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { > + close(fd); > + warn("ioctl(DIOCGDINFO)"); > + return (NULL); > + } > + > + if (memcmp(lab.d_uid, &zero_uid, sizeof(lab.d_uid)) != 0) { > + if (asprintf(&duid, > + > "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c", > +lab.d_uid[0], lab.d_uid[1], lab.d_uid[2], > +lab.d_uid[3], lab.d_uid[4], lab.d_uid[5], > +lab.d_uid[6], lab.d_uid[7], > +path[strlen(path)-1]) == -1) { > + close(fd); > + warn("Cannot malloc duid"); > + return (NULL); > + } > + return (duid); > + } > + } > + > + return (NULL); > } This failed to close fd in the success path; I moved the second close() up to before the memcmp(). > @@ -347,6 +347,13 @@ fstabsearch(char *key) > rn = rawname(fs->fs_spec); > if (rn != NULL && strcmp(rn, key) == 0) > return (fs); > + if (rn != NULL) { > + uid = getduid(rn); > + } else { > + uid = getduid(fs->fs_spec); > + } > + if (uid != NULL && strcmp(uid, key) == 0) > + return (fs); uid is malloced by getduid(), so it needed to be freed here. Nothing big, thanks for doing the hard part! Philip Guenther
Re: [ping] dump -U by default
Philip Guenther writes: > Can we suppress the device form if there's a matching DUID entry? Okay. The DUID/device dance is not that easy (at least for me). So here is a new patch that should work. For your issue, I choose to convert dumpdates entries to DUID (when possible) at read time so dump now has the following features/drawbacks: - All dumpdates entries (of present devices) will be converted to DUID at the next dump (even those that are not being dumped). - Even a dump -w/W tries to opendev the device (in order to find its UID). Index: dump.h === RCS file: /cvs/src/sbin/dump/dump.h,v retrieving revision 1.23 diff -u -p -r1.23 dump.h --- dump.h 3 May 2015 01:44:34 - 1.23 +++ dump.h 12 May 2015 08:42:02 - @@ -125,6 +125,7 @@ __dead void dumpabort(int signo); void getfstab(void); char *rawname(char *cp); +char *getduid(char *path); union dinode *getino(ino_t inum, int *mode); /* rdump routines */ Index: itime.c === RCS file: /cvs/src/sbin/dump/itime.c,v retrieving revision 1.20 diff -u -p -r1.20 itime.c --- itime.c 3 May 2015 01:44:34 - 1.20 +++ itime.c 12 May 2015 08:42:02 - @@ -251,6 +251,11 @@ makedumpdate(struct dumpdates *ddp, char if (sscanf(tbuf, DUMPINFMT, ddp->dd_name, &ddp->dd_level, un_buf) != 3) return(-1); + str = getduid(ddp->dd_name); + if (str != NULL) { + strncpy(ddp->dd_name, str, NAME_MAX+3); + free(str); + } str = strptime(un_buf, "%a %b %e %H:%M:%S %Y", &then); then.tm_isdst = -1; if (str == NULL || (*str != '\n' && *str != '\0')) Index: main.c === RCS file: /cvs/src/sbin/dump/main.c,v retrieving revision 1.55 diff -u -p -r1.55 main.c --- main.c 3 May 2015 01:44:34 - 1.55 +++ main.c 12 May 2015 08:42:02 - @@ -363,7 +363,13 @@ main(int argc, char *argv[]) } } else if ((dt = fstabsearch(disk)) != NULL) { /* in fstab? */ - disk = rawname(dt->fs_spec); + if (strchr(dt->fs_spec, '/')) { + /* fs_spec is a /dev/something */ + disk = rawname(dt->fs_spec); + } else { + /* fs_spec is a DUID */ + disk = rawname(disk); + } mount_point = dt->fs_file; (void)strlcpy(spcl.c_dev, dt->fs_spec, sizeof(spcl.c_dev)); if (dirlist != 0) { @@ -649,13 +655,52 @@ rawname(char *cp) { static char rawbuf[PATH_MAX]; char *dp = strrchr(cp, '/'); + char *prefix; if (dp == NULL) return (NULL); + if (*(dp + 1) == 'r') { + prefix = ""; + } else { + prefix = "r"; + } *dp = '\0'; - (void)snprintf(rawbuf, sizeof(rawbuf), "%s/r%s", cp, dp + 1); + (void)snprintf(rawbuf, sizeof(rawbuf), "%s/%s%s", cp, prefix, dp + 1); *dp = '/'; return (rawbuf); +} + +char * +getduid(char *path) +{ + int fd; + struct disklabel lab; + u_int64_t zero_uid = 0; + char *duid; + + if ((fd = opendev(path, O_RDONLY | O_NOFOLLOW, 0, NULL)) >= 0) { + if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { + close(fd); + warn("ioctl(DIOCGDINFO)"); + return (NULL); + } + + if (memcmp(lab.d_uid, &zero_uid, sizeof(lab.d_uid)) != 0) { + if (asprintf(&duid, + "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c", +lab.d_uid[0], lab.d_uid[1], lab.d_uid[2], +lab.d_uid[3], lab.d_uid[4], lab.d_uid[5], +lab.d_uid[6], lab.d_uid[7], +path[strlen(path)-1]) == -1) { + close(fd); + warn("Cannot malloc duid"); + return (NULL); + } + return (duid); + } + } + + return (NULL); } /* Index: optr.c === RCS file: /cvs/src/sbin/dump/optr.c,v retrieving revision 1.36 diff -u -p -r1.36 optr.c --- optr.c 15 Mar 2015 00:41:27 - 1.36 +++ optr.c 12 May 2015 08:42:02 - @@ -337,7 +337,7 @@ fstabsearch(char *key) { struct pfstab *pf; struct fstab *fs; - char *rn; + char *rn, *uid; for (pf = table; pf != NULL; pf = pf->pf_next) { fs = pf->pf_fstab; @@ -347,6 +347,13 @@ fstabsearch(c
Re: [ping] dump -U by default
On Wed, May 6, 2015 at 4:47 AM, Manuel Giraud wrote: > Minor fix: lastdump was not the only one using fstabsearch. That fills in the filesystem name for DUID entries, but it's still reporting both the device and DUID forms: : morgaine; obj/dump -W Last dump(s) done (Dump '>' file systems): /dev/rsd0f( /usr) Last dump: Level 0, Date Thu Mar 13 10:29 > /dev/rsd0i(/usr/src) Last dump: Level 0, Date Wed Apr 8 11:14 > /dev/rsd0k( /home) Last dump: Level 4, Date Wed Mar 25 00:33 > a7df1ec64e79a49c.i(/usr/src) Last dump: Level 2, Date Wed Apr 15 09:56 > a7df1ec64e79a49c.k( /home) Last dump: Level 6, Date Sat May 2 18:32 : morgaine; Can we suppress the device form if there's a matching DUID entry? Philip Guenther
Re: [ping] dump -U by default
Minor fix: lastdump was not the only one using fstabsearch. Index: dump.h === RCS file: /cvs/src/sbin/dump/dump.h,v retrieving revision 1.23 diff -u -p -r1.23 dump.h --- dump.h 3 May 2015 01:44:34 - 1.23 +++ dump.h 6 May 2015 11:42:54 - @@ -125,6 +125,7 @@ __dead void dumpabort(int signo); void getfstab(void); char *rawname(char *cp); +char *getrealpath(char *path); union dinode *getino(ino_t inum, int *mode); /* rdump routines */ Index: main.c === RCS file: /cvs/src/sbin/dump/main.c,v retrieving revision 1.55 diff -u -p -r1.55 main.c --- main.c 3 May 2015 01:44:34 - 1.55 +++ main.c 6 May 2015 11:42:54 - @@ -363,7 +363,13 @@ main(int argc, char *argv[]) } } else if ((dt = fstabsearch(disk)) != NULL) { /* in fstab? */ - disk = rawname(dt->fs_spec); + if (strchr(dt->fs_spec, '/')) { + /* fs_spec is a /dev/something */ + disk = rawname(dt->fs_spec); + } else { + /* fs_spec is a DUID */ + disk = rawname(disk); + } mount_point = dt->fs_file; (void)strlcpy(spcl.c_dev, dt->fs_spec, sizeof(spcl.c_dev)); if (dirlist != 0) { @@ -656,6 +662,23 @@ rawname(char *cp) (void)snprintf(rawbuf, sizeof(rawbuf), "%s/r%s", cp, dp + 1); *dp = '/'; return (rawbuf); +} + +/* + * Wrapper around opendev(3) to get a realpath of a device. + */ +char * +getrealpath(char *path) +{ + int fd; + char *realpath; + + if ((fd = opendev(path, O_RDONLY | O_NOFOLLOW, 0, + &realpath)) >= 0) { + close(fd); + return (strdup(realpath)); + } + return (NULL); } /* Index: optr.c === RCS file: /cvs/src/sbin/dump/optr.c,v retrieving revision 1.36 diff -u -p -r1.36 optr.c --- optr.c 15 Mar 2015 00:41:27 - 1.36 +++ optr.c 6 May 2015 11:42:54 - @@ -337,7 +337,7 @@ fstabsearch(char *key) { struct pfstab *pf; struct fstab *fs; - char *rn; + char *rn, *rp; for (pf = table; pf != NULL; pf = pf->pf_next) { fs = pf->pf_fstab; @@ -346,6 +346,13 @@ fstabsearch(char *key) return (fs); rn = rawname(fs->fs_spec); if (rn != NULL && strcmp(rn, key) == 0) + return (fs); + rp = getrealpath(key); + if (rn != NULL && rp != NULL && strcmp(rn, rp) == 0) + return (fs); + rp = getrealpath(fs->fs_spec); + rn = rawname(key); + if (rn != NULL && rp != NULL && strcmp(rn, rp) == 0) return (fs); if (key[0] != '/') { if (*fs->fs_spec == '/' && -- Manuel Giraud
Re: [ping] dump -U by default
Philip Guenther writes: > So I'll commit your diff; you wanna switch at doing the matching for > -w/-W ? Ok so hopefully, I think I get this right. With the following /etc/fstab: 8e26a31ab7f46c90.b none swap sw bf16ae2b23dadbc7.a / ffs rw 1 1 swap /tmp tmpfs rw,noexec,nodev,nosuid,-s50m 0 0 bf16ae2b23dadbc7.f /home ffs rw,nodev,nosuid,softdep 1 2 bf16ae2b23dadbc7.e /usr ffs rw,nodev,softdep 1 2 bf16ae2b23dadbc7.d /var ffs rw,nodev,nosuid,softdep 1 2 bf16ae2b23dadbc7.g /usr/src ffs rw,softdep,noauto 0 0 /dev/sd0h /usr/xenocara ffs rw,softdep,noauto 1 0 and /etc/dumpdates: /dev/sd0a 0 Wed Apr 1 10:50:27 2015 /var 0 Wed Apr 1 11:30:05 2015 bf16ae2b23dadbc7.e 0 Fri Apr 24 11:30:09 2015 bf16ae2b23dadbc7.f 0 Fri Apr 24 11:36:42 2015 bf16ae2b23dadbc7.e 1 Tue May 5 12:30:04 2015 bf16ae2b23dadbc7.f 1 Tue May 5 12:30:30 2015 bf16ae2b23dadbc7.h 0 Wed Apr 1 09:56:56 2015 "dump -w" gives: Dump these file systems: /dev/sd0a ( /) Last dump: Level 0, Date Wed Apr 1 10:50 /var ( /var) Last dump: Level 0, Date Wed Apr 1 11:30 bf16ae2b23dadbc7.h(/usr/xenocara) Last dump: Level 0, Date Wed Apr 1 09:56 and "dump -W" gives: Last dump(s) done (Dump '>' file systems): > /dev/sd0a ( /) Last dump: Level 0, Date Wed Apr 1 10:50 > /var ( /var) Last dump: Level 0, Date Wed Apr 1 11:30 bf16ae2b23dadbc7.e( /usr) Last dump: Level 1, Date Tue May 5 12:30 bf16ae2b23dadbc7.f( /home) Last dump: Level 1, Date Tue May 5 12:30 > bf16ae2b23dadbc7.h(/usr/xenocara) Last dump: Level 0, Date Wed Apr 1 > 09:56 Here is the patch: Index: dump.h === RCS file: /cvs/src/sbin/dump/dump.h,v retrieving revision 1.23 diff -u -p -r1.23 dump.h --- dump.h 3 May 2015 01:44:34 - 1.23 +++ dump.h 6 May 2015 09:24:24 - @@ -125,6 +125,7 @@ __dead void dumpabort(int signo); void getfstab(void); char *rawname(char *cp); +char *getrealpath(char *path); union dinode *getino(ino_t inum, int *mode); /* rdump routines */ Index: main.c === RCS file: /cvs/src/sbin/dump/main.c,v retrieving revision 1.55 diff -u -p -r1.55 main.c --- main.c 3 May 2015 01:44:34 - 1.55 +++ main.c 6 May 2015 09:24:24 - @@ -659,6 +659,23 @@ rawname(char *cp) } /* + * Wrapper around opendev(3) to get a realpath of a device. + */ +char * +getrealpath(char *path) +{ + int fd; + char *realpath; + + if ((fd = opendev(path, O_RDONLY | O_NOFOLLOW, 0, + &realpath)) >= 0) { + close(fd); + return (strdup(realpath)); + } + return (NULL); +} + +/* * obsolete -- * Change set of key letters and ordered arguments into something * getopt(3) will like. Index: optr.c === RCS file: /cvs/src/sbin/dump/optr.c,v retrieving revision 1.36 diff -u -p -r1.36 optr.c --- optr.c 15 Mar 2015 00:41:27 - 1.36 +++ optr.c 6 May 2015 09:24:24 - @@ -337,7 +337,7 @@ fstabsearch(char *key) { struct pfstab *pf; struct fstab *fs; - char *rn; + char *rn, *rp; for (pf = table; pf != NULL; pf = pf->pf_next) { fs = pf->pf_fstab; @@ -346,6 +346,13 @@ fstabsearch(char *key) return (fs); rn = rawname(fs->fs_spec); if (rn != NULL && strcmp(rn, key) == 0) + return (fs); + rp = getrealpath(key); + if (rn != NULL && rp != NULL && strcmp(rn, rp) == 0) + return (fs); + rp = getrealpath(fs->fs_spec); + rn = rawname(key); + if (rn != NULL && rp != NULL && strcmp(rn, rp) == 0) return (fs); if (key[0] != '/') { if (*fs->fs_spec == '/' && -- Manuel Giraud
Re: [ping] dump -U by default
On Wed, Apr 15, 2015 at 10:14 AM, Philip Guenther wrote: > On Wed, Apr 15, 2015 at 5:48 AM, Manuel Giraud wrote: >> Here is a patch that eliminate the -U flag for dump and make usage of >> DUID in /etc/dumpdates the default. It also correct old style entries so >> nothing has to be done for the admin :) > > Yeah, I've started using this and it looks good so far. Just a couple > corner cases to verify tonight and presuming it looks good I'll commit > tonight. Heh, "tonight", rght... So the diff itself does what I expect, but running with it has revealed that the -w and -W options need work. Consider this output: : morgaine; dump -w Dump these file systems: /dev/rsd0i(/usr/src) Last dump: Level 0, Date Wed Apr 8 11:14 /dev/rsd0k( /home) Last dump: Level 4, Date Wed Mar 25 00:33 : morgaine; dump -W Last dump(s) done (Dump '>' file systems): /dev/rsd0f( /usr) Last dump: Level 0, Date Thu Mar 13 10:29 > /dev/rsd0i(/usr/src) Last dump: Level 0, Date Wed Apr 8 11:14 > /dev/rsd0k( /home) Last dump: Level 4, Date Wed Mar 25 00:33 a7df1ec64e79a49c.i( ) Last dump: Level 2, Date Wed Apr 15 09:56 a7df1ec64e79a49c.k( ) Last dump: Level 6, Date Sat May 2 18:32 : morgaine; egrep 'src|home' /etc/fstab /dev/sd0k /homeffsro,nodev,softdep 6 2 /dev/sd0i /usr/src ffsro,nodev,nosuid,softdep 6 2 : morgaine; Yes, DUID a7df...49c is sd0, so the dump -w output is incorrect: last dump of /home was just minutes ago, recorded under the DUID. Yes, the output is correct once I change /etc/fstab to use the DUID, but if we're going to automatically switch to DUIDs for /etc/dumpdates then we should match them up automatically too. So I'll commit your diff; you wanna switch at doing the matching for -w/-W ? Philip Guenther
Re: [ping] dump -U by default
> On Wed, Apr 15, 2015 at 5:48 AM, Manuel Giraud wrote: > > Here is a patch that eliminate the -U flag for dump and make usage of > > DUID in /etc/dumpdates the default. It also correct old style entries so > > nothing has to be done for the admin :) > > Yeah, I've started using this and it looks good so far. Just a couple > corner cases to verify tonight and presuming it looks good I'll commit > tonight. Once everything supports duids, the installer can be switched to use DUID by default, without asking the question about non-DUID use. That would be mainly in support of older machines -- we want their return keys to last longer.
Re: [ping] dump -U by default
On Wed, Apr 15, 2015 at 5:48 AM, Manuel Giraud wrote: > Here is a patch that eliminate the -U flag for dump and make usage of > DUID in /etc/dumpdates the default. It also correct old style entries so > nothing has to be done for the admin :) Yeah, I've started using this and it looks good so far. Just a couple corner cases to verify tonight and presuming it looks good I'll commit tonight. Philip Guenther