- Use g_*() API when doing backups.
- fsync() created filed. MFC after: 1 week
This commit is contained in:
parent
2ecb2a01e7
commit
488186c304
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=213059
@ -1081,8 +1081,8 @@ static int
|
|||||||
eli_backup_create(struct gctl_req *req, const char *prov, const char *file)
|
eli_backup_create(struct gctl_req *req, const char *prov, const char *file)
|
||||||
{
|
{
|
||||||
struct g_eli_metadata md;
|
struct g_eli_metadata md;
|
||||||
unsigned secsize;
|
|
||||||
unsigned char *sector;
|
unsigned char *sector;
|
||||||
|
ssize_t secsize;
|
||||||
off_t mediasize;
|
off_t mediasize;
|
||||||
int filefd, provfd, ret;
|
int filefd, provfd, ret;
|
||||||
|
|
||||||
@ -1091,13 +1091,7 @@ eli_backup_create(struct gctl_req *req, const char *prov, const char *file)
|
|||||||
sector = NULL;
|
sector = NULL;
|
||||||
secsize = 0;
|
secsize = 0;
|
||||||
|
|
||||||
provfd = open(prov, O_RDONLY);
|
provfd = g_open(prov, 0);
|
||||||
if (provfd == -1 && errno == ENOENT && prov[0] != '/') {
|
|
||||||
char devprov[MAXPATHLEN];
|
|
||||||
|
|
||||||
snprintf(devprov, sizeof(devprov), "%s%s", _PATH_DEV, prov);
|
|
||||||
provfd = open(devprov, O_RDONLY);
|
|
||||||
}
|
|
||||||
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;
|
||||||
@ -1108,9 +1102,9 @@ eli_backup_create(struct gctl_req *req, const char *prov, const char *file)
|
|||||||
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;
|
||||||
@ -1123,8 +1117,7 @@ eli_backup_create(struct gctl_req *req, const char *prov, const char *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read metadata from the provider. */
|
/* Read metadata from the provider. */
|
||||||
if (pread(provfd, sector, secsize, mediasize - secsize) !=
|
if (pread(provfd, sector, secsize, mediasize - secsize) != secsize) {
|
||||||
(ssize_t)secsize) {
|
|
||||||
gctl_error(req, "Cannot read metadata: %s.", strerror(errno));
|
gctl_error(req, "Cannot read metadata: %s.", strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -1134,18 +1127,19 @@ eli_backup_create(struct gctl_req *req, const char *prov, const char *file)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
/* Write metadata to the destination file. */
|
/* Write metadata to the destination file. */
|
||||||
if (write(filefd, sector, secsize) != (ssize_t)secsize) {
|
if (write(filefd, sector, secsize) != secsize) {
|
||||||
gctl_error(req, "Cannot write to %s: %s.", file,
|
gctl_error(req, "Cannot write to %s: %s.", file,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
(void)fsync(filefd);
|
||||||
/* Success. */
|
/* Success. */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user