Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=63bd2eff20…
Commit: 63bd2eff2043c2d14399d5511e116ae0cdd8bba3
Parent: 3c8db52fe77267109a6f01c178370747a23e64fd
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Sat Nov 16 02:19:07 2013 -0600
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon Nov 18 10:49:49 2013 +0000
Switch is_pathname_mounted callers to lgfs2_open_mnt*
Use the new lgfs2_open_mnt* functions in fsck.gfs2, gfs2_grow, and gfs2_jadd.
Resolves: bz#991204
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/fsck/initialize.c | 30 ++++++++++++------------------
gfs2/mkfs/main_grow.c | 31 ++++++++++++-------------------
gfs2/mkfs/main_jadd.c | 17 +++++++++--------
3 files changed, 33 insertions(+), 45 deletions(-)
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 6612fe7..5758607 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -1475,8 +1475,7 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
sdp->device_fd = open(opts.device, open_flag);
if (sdp->device_fd < 0) {
- int is_mounted, ro;
-
+ struct mntent *mnt;
if (open_flag == O_RDONLY || errno != EBUSY) {
log_crit( _("Unable to open device: %s\n"),
opts.device);
@@ -1485,30 +1484,23 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
/* We can't open it EXCL. It may be already open rw (in which
case we want to deny them access) or it may be mounted as
the root file system at boot time (in which case we need to
- allow it.) We use is_pathname_mounted here even though
- we're specifying a device name, not a path name. The
- function checks for device as well. */
- strncpy(sdp->device_name, opts.device,
- sizeof(sdp->device_name));
- sdp->path_name = sdp->device_name; /* This gets overwritten */
- is_mounted = is_pathname_mounted(sdp->path_name, sdp->device_name, &ro);
- /* If the device is busy, but not because it's mounted, fail.
+ allow it.)
+ If the device is busy, but not because it's mounted, fail.
This protects against cases where the file system is LVM
- and perhaps mounted on a different node. */
- if (!is_mounted)
+ and perhaps mounted on a different node.
+ Try opening without O_EXCL. */
+ sdp->device_fd = lgfs2_open_mnt_dev(opts.device, O_RDWR, &mnt);
+ if (sdp->device_fd < 0)
goto mount_fail;
/* If the device is mounted, but not mounted RO, fail. This
protects them against cases where the file system is
mounted RW, but still allows us to check our own root
file system. */
- if (!ro)
- goto mount_fail;
+ if (!hasmntopt(mnt, MNTOPT_RO))
+ goto close_fail;
/* The device is mounted RO, so it's likely our own root
file system. We can only do so much to protect the users
- from themselves. Try opening without O_EXCL. */
- if ((sdp->device_fd = open(opts.device, O_RDWR)) < 0)
- goto mount_fail;
-
+ from themselves. */
was_mounted_ro = 1;
}
@@ -1591,6 +1583,8 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
return FSCK_OK;
+close_fail:
+ close(sdp->device_fd);
mount_fail:
log_crit( _("Device %s is busy.\n"), opts.device);
return FSCK_USAGE;
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 5db91d9..541b0f2 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -323,7 +323,7 @@ main_grow(int argc, char *argv[])
int rgcount, rindex_fd;
char rindex_name[PATH_MAX];
int error = EXIT_SUCCESS;
- int ro_mnt = 0;
+ int devflags = (test ? O_RDONLY : O_RDWR) | O_CLOEXEC;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->bsize = GFS2_DEFAULT_BSIZE;
@@ -333,30 +333,23 @@ main_grow(int argc, char *argv[])
sdp->md.journals = 1;
decode_arguments(argc, argv, sdp);
- while ((argc - optind) > 0) {
+ for(; (argc - optind) > 0; optind++) {
int sane;
+ struct mntent *mnt;
struct rgrp_tree *last_rgrp;
- strncpy(sdp->device_name, argv[optind], PATH_MAX - 1);
- sdp->path_name = argv[optind++];
-
- if ((!is_pathname_mounted(sdp->path_name, sdp->device_name, &ro_mnt))) {
- perror(sdp->path_name);
- exit(EXIT_FAILURE);
- }
-
- sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
- if (sdp->path_fd < 0){
- perror(sdp->path_name);
+ error = lgfs2_open_mnt(argv[optind], O_RDONLY|O_CLOEXEC, &sdp->path_fd,
+ devflags, &sdp->device_fd, &mnt);
+ if (error != 0) {
+ fprintf(stderr, _("Error looking up mount '%s': %s\n"), argv[optind], strerror(errno));
exit(EXIT_FAILURE);
}
-
- sdp->device_fd = open(sdp->device_name,
- (test ? O_RDONLY : O_RDWR) | O_CLOEXEC);
- if (sdp->device_fd < 0){
- perror(sdp->device_name);
- exit(EXIT_FAILURE);
+ if (mnt == NULL) {
+ fprintf(stderr, _("%s: not a mounted gfs2 file system\n"), argv[optind]);
+ continue;
}
+ sdp->path_name = mnt->mnt_dir;
+ strncpy(sdp->device_name, mnt->mnt_fsname, PATH_MAX - 1);
if (lgfs2_get_dev_info(sdp->device_fd, &sdp->dinfo) < 0) {
perror(sdp->device_name);
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index b6cd8e4..815dd52 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -490,8 +490,8 @@ add_j(struct gfs2_sbd *sdp)
void main_jadd(int argc, char *argv[])
{
struct gfs2_sbd sbd, *sdp = &sbd;
+ struct mntent *mnt;
unsigned int total;
- int ro_mnt = 0;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->jsize = GFS2_DEFAULT_JSIZE;
@@ -500,17 +500,18 @@ void main_jadd(int argc, char *argv[])
decode_arguments(argc, argv, sdp);
verify_arguments(sdp);
-
- sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
- if (sdp->path_fd < 0){
- perror(sdp->path_name);
+
+ sbd.path_fd = lgfs2_open_mnt_dir(sbd.path_name, O_RDONLY|O_CLOEXEC, &mnt);
+ if (sbd.path_fd < 0) {
+ fprintf(stderr, _("Error looking up mount '%s': %s\n"), sbd.path_name, strerror(errno));
exit(EXIT_FAILURE);
}
-
- if (!is_pathname_mounted(sdp->path_name, sdp->device_name, &ro_mnt)) {
- perror(sdp->path_name);
+ if (mnt == NULL) {
+ fprintf(stderr, _("%s: not a mounted gfs2 file system\n"), sbd.path_name);
exit(EXIT_FAILURE);
}
+ sbd.path_name = mnt->mnt_dir;
+ strncpy(sbd.device_name, mnt->mnt_fsname, PATH_MAX - 1);
gather_info(sdp);
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=ad11e277eb…
Commit: ad11e277ebd8d01a1b0a29ee9f697ba90c8577a4
Parent: 25c6e51bb4d083eb341bbc8541bb2ad278988f10
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Sat Nov 16 02:19:07 2013 -0600
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Sat Nov 16 02:19:07 2013 -0600
Switch is_pathname_mounted callers to lgfs2_open_mnt*
Use the new lgfs2_open_mnt* functions in fsck.gfs2, gfs2_grow, and gfs2_jadd.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/fsck/initialize.c | 30 ++++++++++++------------------
gfs2/mkfs/main_grow.c | 31 ++++++++++++-------------------
gfs2/mkfs/main_jadd.c | 17 +++++++++--------
3 files changed, 33 insertions(+), 45 deletions(-)
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 6612fe7..5758607 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -1475,8 +1475,7 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
sdp->device_fd = open(opts.device, open_flag);
if (sdp->device_fd < 0) {
- int is_mounted, ro;
-
+ struct mntent *mnt;
if (open_flag == O_RDONLY || errno != EBUSY) {
log_crit( _("Unable to open device: %s\n"),
opts.device);
@@ -1485,30 +1484,23 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
/* We can't open it EXCL. It may be already open rw (in which
case we want to deny them access) or it may be mounted as
the root file system at boot time (in which case we need to
- allow it.) We use is_pathname_mounted here even though
- we're specifying a device name, not a path name. The
- function checks for device as well. */
- strncpy(sdp->device_name, opts.device,
- sizeof(sdp->device_name));
- sdp->path_name = sdp->device_name; /* This gets overwritten */
- is_mounted = is_pathname_mounted(sdp->path_name, sdp->device_name, &ro);
- /* If the device is busy, but not because it's mounted, fail.
+ allow it.)
+ If the device is busy, but not because it's mounted, fail.
This protects against cases where the file system is LVM
- and perhaps mounted on a different node. */
- if (!is_mounted)
+ and perhaps mounted on a different node.
+ Try opening without O_EXCL. */
+ sdp->device_fd = lgfs2_open_mnt_dev(opts.device, O_RDWR, &mnt);
+ if (sdp->device_fd < 0)
goto mount_fail;
/* If the device is mounted, but not mounted RO, fail. This
protects them against cases where the file system is
mounted RW, but still allows us to check our own root
file system. */
- if (!ro)
- goto mount_fail;
+ if (!hasmntopt(mnt, MNTOPT_RO))
+ goto close_fail;
/* The device is mounted RO, so it's likely our own root
file system. We can only do so much to protect the users
- from themselves. Try opening without O_EXCL. */
- if ((sdp->device_fd = open(opts.device, O_RDWR)) < 0)
- goto mount_fail;
-
+ from themselves. */
was_mounted_ro = 1;
}
@@ -1591,6 +1583,8 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
return FSCK_OK;
+close_fail:
+ close(sdp->device_fd);
mount_fail:
log_crit( _("Device %s is busy.\n"), opts.device);
return FSCK_USAGE;
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 5db91d9..541b0f2 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -323,7 +323,7 @@ main_grow(int argc, char *argv[])
int rgcount, rindex_fd;
char rindex_name[PATH_MAX];
int error = EXIT_SUCCESS;
- int ro_mnt = 0;
+ int devflags = (test ? O_RDONLY : O_RDWR) | O_CLOEXEC;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->bsize = GFS2_DEFAULT_BSIZE;
@@ -333,30 +333,23 @@ main_grow(int argc, char *argv[])
sdp->md.journals = 1;
decode_arguments(argc, argv, sdp);
- while ((argc - optind) > 0) {
+ for(; (argc - optind) > 0; optind++) {
int sane;
+ struct mntent *mnt;
struct rgrp_tree *last_rgrp;
- strncpy(sdp->device_name, argv[optind], PATH_MAX - 1);
- sdp->path_name = argv[optind++];
-
- if ((!is_pathname_mounted(sdp->path_name, sdp->device_name, &ro_mnt))) {
- perror(sdp->path_name);
- exit(EXIT_FAILURE);
- }
-
- sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
- if (sdp->path_fd < 0){
- perror(sdp->path_name);
+ error = lgfs2_open_mnt(argv[optind], O_RDONLY|O_CLOEXEC, &sdp->path_fd,
+ devflags, &sdp->device_fd, &mnt);
+ if (error != 0) {
+ fprintf(stderr, _("Error looking up mount '%s': %s\n"), argv[optind], strerror(errno));
exit(EXIT_FAILURE);
}
-
- sdp->device_fd = open(sdp->device_name,
- (test ? O_RDONLY : O_RDWR) | O_CLOEXEC);
- if (sdp->device_fd < 0){
- perror(sdp->device_name);
- exit(EXIT_FAILURE);
+ if (mnt == NULL) {
+ fprintf(stderr, _("%s: not a mounted gfs2 file system\n"), argv[optind]);
+ continue;
}
+ sdp->path_name = mnt->mnt_dir;
+ strncpy(sdp->device_name, mnt->mnt_fsname, PATH_MAX - 1);
if (lgfs2_get_dev_info(sdp->device_fd, &sdp->dinfo) < 0) {
perror(sdp->device_name);
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index b6cd8e4..815dd52 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -490,8 +490,8 @@ add_j(struct gfs2_sbd *sdp)
void main_jadd(int argc, char *argv[])
{
struct gfs2_sbd sbd, *sdp = &sbd;
+ struct mntent *mnt;
unsigned int total;
- int ro_mnt = 0;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->jsize = GFS2_DEFAULT_JSIZE;
@@ -500,17 +500,18 @@ void main_jadd(int argc, char *argv[])
decode_arguments(argc, argv, sdp);
verify_arguments(sdp);
-
- sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
- if (sdp->path_fd < 0){
- perror(sdp->path_name);
+
+ sbd.path_fd = lgfs2_open_mnt_dir(sbd.path_name, O_RDONLY|O_CLOEXEC, &mnt);
+ if (sbd.path_fd < 0) {
+ fprintf(stderr, _("Error looking up mount '%s': %s\n"), sbd.path_name, strerror(errno));
exit(EXIT_FAILURE);
}
-
- if (!is_pathname_mounted(sdp->path_name, sdp->device_name, &ro_mnt)) {
- perror(sdp->path_name);
+ if (mnt == NULL) {
+ fprintf(stderr, _("%s: not a mounted gfs2 file system\n"), sbd.path_name);
exit(EXIT_FAILURE);
}
+ sbd.path_name = mnt->mnt_dir;
+ strncpy(sbd.device_name, mnt->mnt_fsname, PATH_MAX - 1);
gather_info(sdp);
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=5e4fe097ac…
Commit: 5e4fe097ac39ceb8e6768da98cd1e84ff99b8176
Parent: 32d72eb22fdf00c759df50e5fce49292d15be5ed
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Tue Nov 12 16:38:34 2013 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue Nov 12 17:26:00 2013 +0000
gfs2l: Build with -D_FILE_OFFSET_BITS=64
The latest test cases were failing on 32-bit architectures as gfs2l
wasn't being built with large file support. This adds
-D_FILE_OFFSET_BITS=64 to fix the tests.
Resolves: bz#1028388
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/Makefile.am | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gfs2/libgfs2/Makefile.am b/gfs2/libgfs2/Makefile.am
index b57f6d9..c5cb288 100644
--- a/gfs2/libgfs2/Makefile.am
+++ b/gfs2/libgfs2/Makefile.am
@@ -22,7 +22,7 @@ libgfs2_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 \
-I$(top_srcdir)/gfs2/include
gfs2l_SOURCES = gfs2l.c
-gfs2l_CPPFLAGS = -I$(top_srcdir)/gfs2/include
+gfs2l_CPPFLAGS = -I$(top_srcdir)/gfs2/include -D_FILE_OFFSET_BITS=64
gfs2l_LDADD = libgfs2.la
# Autotools can't handle header files output by flex so we have to generate it manually