diff options
author | Karel Zak | 2017-09-15 14:30:06 +0200 |
---|---|---|
committer | Karel Zak | 2017-09-15 14:30:06 +0200 |
commit | d369dc42cb4974d6a928ae28ed32fa11b528e5fb (patch) | |
tree | ffa3e5f491285c84cc5cad85d73b929917fabc30 /libmount | |
parent | libsmartcols: fix heap-buffer-overflow when move columns (diff) | |
download | kernel-qcow2-util-linux-d369dc42cb4974d6a928ae28ed32fa11b528e5fb.tar.gz kernel-qcow2-util-linux-d369dc42cb4974d6a928ae28ed32fa11b528e5fb.tar.xz kernel-qcow2-util-linux-d369dc42cb4974d6a928ae28ed32fa11b528e5fb.zip |
libmount: export locking errors as MNT_EX_FILEIO
The mount man page assumes locking errors mapped to MNT_EX_FILEIO (16)
return code. Unfortunately, this is internally not exported as a
special error code, so it's returned as a generic (errno based)
stuff. This patch fixes this issue.
Note that we still use locking for example for utab or when enabled
/etc/mtab (disabled by default).
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount')
-rw-r--r-- | libmount/src/context_mount.c | 11 | ||||
-rw-r--r-- | libmount/src/context_umount.c | 11 | ||||
-rw-r--r-- | libmount/src/libmount.h.in | 8 | ||||
-rw-r--r-- | libmount/src/tab_update.c | 17 |
4 files changed, 37 insertions, 10 deletions
diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 65f7dbfd0..e84947f00 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -1379,6 +1379,10 @@ int mnt_context_get_mount_excode( if (buf) snprintf(buf, bufsz, _("overlapping loop device exists for %s"), src); return MNT_EX_FAIL; + case -MNT_ERR_LOCK: + if (buf) + snprintf(buf, bufsz, _("locking failed")); + return MNT_EX_FILEIO; default: return mnt_context_get_generic_excode(rc, buf, bufsz, _("mount failed: %m")); } @@ -1388,7 +1392,12 @@ int mnt_context_get_mount_excode( * mount(2) syscall success, but something else failed * (probably error in mtab processing). */ - if (rc < 0) + if (rc == -MNT_ERR_LOCK) { + if (buf) + snprintf(buf, bufsz, _("filesystem was mounted, but failed to update userspace mount table")); + return MNT_EX_FILEIO; + + } else if (rc < 0) return mnt_context_get_generic_excode(rc, buf, bufsz, _("filesystem was mounted, but any subsequent operation failed: %m")); diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index f2c304f4a..a8124629f 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -1063,6 +1063,10 @@ int mnt_context_get_umount_excode( if (buf) snprintf(buf, bufsz, _("not mounted")); return MNT_EX_USAGE; + } else if (rc == -MNT_ERR_LOCK) { + if (buf) + snprintf(buf, bufsz, _("locking failed")); + return MNT_EX_FILEIO; } return mnt_context_get_generic_excode(rc, buf, bufsz, _("umount failed: %m")); @@ -1072,7 +1076,12 @@ int mnt_context_get_umount_excode( * umount(2) syscall success, but something else failed * (probably error in mtab processing). */ - if (rc < 0) + if (rc == -MNT_ERR_LOCK) { + if (buf) + snprintf(buf, bufsz, _("filesystem was unmounted, but failed to update userspace mount table")); + return MNT_EX_FILEIO; + + } else if (rc < 0) return mnt_context_get_generic_excode(rc, buf, bufsz, _("filesystem was unmounted, but any subsequent operation failed: %m")); diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in index 123145fc4..463b8ddcc 100644 --- a/libmount/src/libmount.h.in +++ b/libmount/src/libmount.h.in @@ -184,6 +184,12 @@ enum { * detected overlapping loop device that cannot be re-used */ #define MNT_ERR_LOOPOVERLAP 5007 +/** + * MNT_ERR_LOCK: + * + * failed to lock mtab/utab or so. + */ +#define MNT_ERR_LOCK 5008 /* @@ -230,7 +236,7 @@ enum { /** * MNT_EX_FILEIO: * - * [u]mount(8) exit code: problems writing, locking, ... mtab/fstab + * [u]mount(8) exit code: problems writing, locking, ... mtab/utab */ #define MNT_EX_FILEIO 16 diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c index 52e1dd444..e95713301 100644 --- a/libmount/src/tab_update.c +++ b/libmount/src/tab_update.c @@ -696,7 +696,7 @@ static int update_add_entry(struct libmnt_update *upd, struct libmnt_lock *lc) if (lc) rc = mnt_lock_file(lc); if (rc) - return rc; + return -MNT_ERR_LOCK; tb = __mnt_new_table_from_file(upd->filename, upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB); @@ -722,7 +722,7 @@ static int update_remove_entry(struct libmnt_update *upd, struct libmnt_lock *lc if (lc) rc = mnt_lock_file(lc); if (rc) - return rc; + return -MNT_ERR_LOCK; tb = __mnt_new_table_from_file(upd->filename, upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB); @@ -751,7 +751,7 @@ static int update_modify_target(struct libmnt_update *upd, struct libmnt_lock *l if (lc) rc = mnt_lock_file(lc); if (rc) - return rc; + return -MNT_ERR_LOCK; tb = __mnt_new_table_from_file(upd->filename, upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB); @@ -788,7 +788,7 @@ static int update_modify_options(struct libmnt_update *upd, struct libmnt_lock * if (lc) rc = mnt_lock_file(lc); if (rc) - return rc; + return -MNT_ERR_LOCK; tb = __mnt_new_table_from_file(upd->filename, upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB); @@ -885,10 +885,13 @@ int mnt_update_already_done(struct libmnt_update *upd, struct libmnt_lock *lc) } if (lc && upd->userspace_only) mnt_lock_use_simplelock(lc, TRUE); /* use flock */ - if (lc) + if (lc) { rc = mnt_lock_file(lc); - if (rc) - goto done; + if (rc) { + rc = -MNT_ERR_LOCK; + goto done; + } + } tb = __mnt_new_table_from_file(upd->filename, upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB); |