Update errno codes for lvm_vg_open() and internal vg_read()
cover Update errno codes for lvm_vg_open() and internal vg_read()
Update some errno values for lvm_vg_open() and vg_read() calls. I looked through the errno codes and the attached patch was the best fit I could find for the different error paths in _vg_lock_and_read().
Addresses http://www.redhat.com/archives/linux-lvm/2010-November/msg00081.html
PATCH 1/2 Update errno codes for vg_read() and lvm2app lvm_vg_open().
Update errno codes for vg_read error paths:
- EINVAL: invalid vg_name
- ENOLCK: lock_vol fails
- ENODEV: VG 'vgname' does not exist
- EPROTOTYPE: VG is clustered but locking not clustered
- EROFS: VG is read-only
- EUCLEAN: VG is inconsistent
--- lib/metadata/metadata.c | 23 ++++++++++++++--------- liblvm/lvm2app.h | 8 ++++++++ 2 files changed, 22 insertions(+), 9 deletions(-)
lib/metadata/metadata.c +14 -9
@@ -3532,7 +3532,8 @@ static uint32_t _vg_bad_status_bits(const struct volume_group *vg,if ((status &CLUSTERED ) && (vg_is_clustered (vg)) && !locking_is_clustered ()) { -log_error ("Skipping clustered volume group %s" , vg->name); +log_errno (EPROTOTYPE , +"Skipping clustered volume group %s" , vg->name);/* Return because other flags are considered undefined. */ return FAILED_CLUSTERED ; }
@@ -3545,7 +3546,7 @@ static uint32_t _vg_bad_status_bits(const struct volume_group *vg,if ((status &LVM_WRITE ) && !(vg->status &LVM_WRITE )) { -log_error ("Volume group %s is read-only" , vg->name); +log_errno (EROFS ,"Volume group %s is read-only" , vg->name); failure |=FAILED_READ_ONLY ; }
@@ -3617,7 +3618,7 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha consistent =0 ;if (!validate_name (vg_name) && !is_orphan_vg (vg_name)) { -log_error ("Volume group name %s has invalid characters" , +log_errno (EINVAL ,"Volume group name %s has invalid characters" , vg_name);return NULL ; }
@@ -3626,7 +3627,7 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const chaif (!already_locked && !(misc_flags &READ_WITHOUT_LOCK ) && !lock_vol (cmd, vg_name, lock_flags)) { -log_error ("Can't get lock for %s" , vg_name); +log_errno (ENOLCK ,"Can't get lock for %s" , vg_name);return _vg_make_handle (cmd, vg,FAILED_LOCKING ); }
@@ -3638,19 +3639,21 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha/* If consistent == 1, we get NULL here if correction fails. */ if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) {if (consistent_in && !consistent) { -log_error ("Volume group \"%s\" inconsistent." , vg_name); +log_errno (EUCLEAN , +"Volume group \"%s\" inconsistent." , vg_name); failure |=FAILED_INCONSISTENT ; goto_bad; } -log_error ("Volume group \"%s\" not found" , vg_name); +log_errno (ENODEV ,"Volume group \"%s\" not found" , vg_name); failure |=FAILED_NOTFOUND ; goto_bad; }if (vg_is_clustered (vg) && !locking_is_clustered ()) { -log_error ("Skipping clustered volume group %s" , vg->name); +log_errno (EPROTOTYPE , +"Skipping clustered volume group %s" , vg->name); failure |=FAILED_CLUSTERED ; goto_bad; }
@@ -3659,7 +3662,8 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const chaif (!consistent && !failure) {vg_release (vg);if (!(vg =_recover_vg (cmd, vg_name, vgid))) { -log_error ("Recovery of volume group \"%s\" failed." , +log_errno (EUCLEAN , +"Recovery of volume group \"%s\" failed." , vg_name); failure |=FAILED_INCONSISTENT ; goto_bad;
@@ -3681,7 +3685,8 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const chaif (!cmd->handles_unknown_segments &&vg_has_unknown_segments (vg) && lock_flags ==LCK_VG_WRITE ) { -log_error ("Cannot change VG %s with unknown segments in it!" , +log_errno (EUCLEAN , +"Cannot change VG %s with unknown segments in it!" , vg->name); failure |=FAILED_INCONSISTENT ;/* FIXME new failure code here? */ goto_bad;
liblvm/lvm2app.h +8 -0
@@ -466,6 +466,14 @@ const char *lvm_vgname_from_device(lvm_t libh, const char *device);* Open flags - currently ignored. * * \return non-NULL VG handle (success) or NULL (failure). +* In the case of a failure, lvm_errno() may be used to retrieve the specific +* error. The errno codes for various errors are as follows: +* EINVAL: Invalid characters in 'vgname' or 'mode'. +* ENOLCK: Unable to obtain VG lock. +* ENODEV: Unable to find 'vgname' on system. +* EPROTOTYPE: Volume group 'vgname' is clustered but locking not clustered. +* EROFS: Volume group 'vgname' is read-only +* EUCLEAN: Volume group 'vgname' inconsistent */ vg_t lvm_vg_open (lvm_t libh,const char *vgname,const char *mode,uint32_t flags);
Signature · 1 line
1.7.2.2
PATCH 1/2 Update errno codes for vg_read() and lvm2app lvm_vg_open().
Hi,
I am not checking this in yet, I would like to discuss the value choices first a bit. Presumably, once we set them, we are sort of stuck with the choices, so we should be careful.
Quoted 3 lines · Dave Wysochanski
Update errno codes for
vg_readerror paths:
- EINVAL: invalidvg_name
- ENOLCK:lock_volfails
EBUSY? (But really, this probably depends on *why* _lock_vol failed... maybe we need to drill down here?)
Quoted 2 lines
- ENODEV: VG 'vgname' does not exist
- EPROTOTYPE: VG is clustered but locking not clustered
What about just EPROTO? Or ENOLCK?
Quoted 1 line
- EROFS: VG is read-only
If we want to re-use existing errnos, I would go with EACCESS or EPERM here. EROFS *sounds* similar, but is IMHO a semantical misfit.
Quoted 1 line
- EUCLEAN: VG is inconsistent
This one is tricky. I would almost not assign an errno here at least for now.
Yours,
Petr.
PATCH 1/2 Update errno codes for vg_read() and lvm2app lvm_vg_open().
Meant to send to the list - my responses to Petr below.
----- Forwarded Message ----
Quoted 95 lines
From: Dave W <[email protected]>
To: Petr Rockai <[email protected]>
Sent: Fri, November 26, 2010 12:55:36 PM
Subject: Re: [lvm-devel] [PATCH 1/2] Update errno codes forvg_read()and lvm2applvm_vg_open().----- Original Message ----
Quoted 13 lines
From: Petr Rockai <[email protected]>
To: lvm-devel at redhat.com
Cc: benscott at nwlink.com; Dave Wysochanski <[email protected]>
Sent: Thu, November 25, 2010 9:48:28 AM
Subject: Re: [lvm-devel] [PATCH 1/2] Update errno codes forvg_read()and lvm2applvm_vg_open().Hi,
I am not checking this in yet, I would like to discuss the value choices first a bit. Presumably, once we set them, we are sort of stuck with the choices, so we should be careful.
Quoted 8 lines
Quoted 3 lines · Dave Wysochanski
Update errno codes for
vg_readerror paths:
- EINVAL: invalidvg_name
- ENOLCK:lock_volfailsEBUSY? (But really, this probably depends on *why*
_lock_volfailed... maybe we need to drill down here?)For this patch I was just concerning myself with the top-most error path, and trying to ensure errno was set to something sane for each path. I don't think EBUSY fits as well at this high of a level.
Keep in mind the motivation for this change came with the bug reported by Ben who was using lvm2app and asked for a specific code for the "skipping clustered VG" case. So I expanded the scope to include most all paths of
lvm_vg_open().It may be worth drilling down here and setting errno inside
lock_vol(). If this is the case, we should maybe split this errno code into a separate patch?Quoted 4 lines
Quoted 2 lines
- ENODEV: VG 'vgname' does not exist
- EPROTOTYPE: VG is clustered but locking not clusteredWhat about just EPROTO? Or ENOLCK?
This was the one that was the motivation for the patch. I think there are multiple reasonable possibilities here, none of which really fits 100%. Some others I thought might fit too, such as ENOPROTOOPT ("protocol not available"), EPROTO ("protocol error").
I guess one might want to think about the other possible cluster errors we could get in this function and how they
might want to map to errnos. Such a process runs the risk
of taking a long time to complete though.Quoted 4 lines
Quoted 1 line
- EROFS: VG is read-only
If we want to re-use existing errnos, I would go with EACCESS or EPERM here. EROFS *sounds* similar, but is IMHO a semantical misfit.
I think EACCESS or EPERM would fit as well, and as you say may be better than
EROFS.
I guess I thought of "read only" being the most specific to that path for thatcall and less
likely to conflict. The fact we are limited in errno values we have to try tothink about
what other codes we might need. You may want to reserve EPERM for a day whenfor
instance a user gives a value of 'flags' that are invalid. In the end it is hard to predict
the future though.Quoted 4 lines
Quoted 1 line
- EUCLEAN: VG is inconsistent
This one is tricky. I would almost not assign an errno here at least for now.
Might be another good candidate for a separate patch. As you know, the inconsistent
VG case is probably a very important one once recovery APIs are added to lvm2app.
PATCH 2/2 Update interactive tests to display lvm_vg_open errno code.
In reply to Dave WysochanskiShow errno code if lvm_vg_open() fails.
--- test/api/test.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
test/api/test.c +2 -1
@@ -349,7 +349,8 @@ static void _vg_open(char **argv, int argc, lvm_t libh)else vg =lvm_vg_open (libh, argv[1 ], argv[2 ],0 );if (!vg || !lvm_vg_get_name (vg)) { -printf ("Error opening %s\n" , argv[1 ]); +printf ("Error opening %s, errno = %d\n" , + argv[1 ],lvm_errno (libh));return ; }
Signature · 1 line
1.7.2.2