- Make use of g_*() API.
- Flush cache after writing metadata. MFC after: 1 week
This commit is contained in:
parent
5cd61a1fb7
commit
429cf66400
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=213057
@ -1176,7 +1176,7 @@ eli_restore(struct gctl_req *req)
|
|||||||
struct g_eli_metadata md;
|
struct g_eli_metadata md;
|
||||||
const char *file, *prov;
|
const char *file, *prov;
|
||||||
unsigned char *sector;
|
unsigned char *sector;
|
||||||
unsigned secsize;
|
ssize_t secsize;
|
||||||
off_t mediasize;
|
off_t mediasize;
|
||||||
int nargs, filefd, provfd;
|
int nargs, filefd, provfd;
|
||||||
|
|
||||||
@ -1197,21 +1197,15 @@ eli_restore(struct gctl_req *req)
|
|||||||
gctl_error(req, "Cannot open %s: %s.", file, strerror(errno));
|
gctl_error(req, "Cannot open %s: %s.", file, strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
provfd = open(prov, O_WRONLY);
|
provfd = g_open(prov, 1);
|
||||||
if (provfd == -1 && errno == ENOENT && prov[0] != '/') {
|
|
||||||
char devprov[MAXPATHLEN];
|
|
||||||
|
|
||||||
snprintf(devprov, sizeof(devprov), "%s%s", _PATH_DEV, prov);
|
|
||||||
provfd = open(devprov, O_WRONLY);
|
|
||||||
}
|
|
||||||
if (provfd == -1) {
|
if (provfd == -1) {
|
||||||
gctl_error(req, "Cannot open %s: %s.", prov, strerror(errno));
|
gctl_error(req, "Cannot open %s: %s.", prov, strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
mediasize = g_get_mediasize(prov);
|
mediasize = g_mediasize(provfd);
|
||||||
secsize = g_get_sectorsize(prov);
|
secsize = g_sectorsize(provfd);
|
||||||
if (mediasize == 0 || secsize == 0) {
|
if (mediasize == -1 || secsize == -1) {
|
||||||
gctl_error(req, "Cannot get informations about %s: %s.", prov,
|
gctl_error(req, "Cannot get informations about %s: %s.", prov,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
@ -1224,7 +1218,7 @@ eli_restore(struct gctl_req *req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read metadata from the backup file. */
|
/* Read metadata from the backup file. */
|
||||||
if (read(filefd, sector, secsize) != (ssize_t)secsize) {
|
if (read(filefd, sector, secsize) != secsize) {
|
||||||
gctl_error(req, "Cannot read from %s: %s.", file,
|
gctl_error(req, "Cannot read from %s: %s.", file,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
@ -1246,16 +1240,16 @@ eli_restore(struct gctl_req *req)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Write metadata from the provider. */
|
/* Write metadata from the provider. */
|
||||||
if (pwrite(provfd, sector, secsize, mediasize - secsize) !=
|
if (pwrite(provfd, sector, secsize, mediasize - secsize) != secsize) {
|
||||||
(ssize_t)secsize) {
|
|
||||||
gctl_error(req, "Cannot write metadata: %s.", strerror(errno));
|
gctl_error(req, "Cannot write metadata: %s.", strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
(void)g_flush(provfd);
|
||||||
out:
|
out:
|
||||||
if (provfd > 0)
|
if (provfd >= 0)
|
||||||
close(provfd);
|
(void)g_close(provfd);
|
||||||
if (filefd > 0)
|
if (filefd >= 0)
|
||||||
close(filefd);
|
(void)close(filefd);
|
||||||
if (sector != NULL) {
|
if (sector != NULL) {
|
||||||
bzero(sector, secsize);
|
bzero(sector, secsize);
|
||||||
free(sector);
|
free(sector);
|
||||||
@ -1341,6 +1335,7 @@ eli_resize(struct gctl_req *req)
|
|||||||
gctl_error(req, "Cannot write metadata: %s.", strerror(errno));
|
gctl_error(req, "Cannot write metadata: %s.", strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
(void)g_flush(provfd);
|
||||||
|
|
||||||
/* Now trash the old metadata. */
|
/* Now trash the old metadata. */
|
||||||
arc4rand(sector, secsize);
|
arc4rand(sector, secsize);
|
||||||
|
Loading…
Reference in New Issue
Block a user