From: Markus Armbruster <armbru@redhat.com>
To: Gonglei <arei.gonglei@hotmail.com>
Cc: peter.maydell@linaro.org, weidong.huang@huawei.com,
qemu-trivial@nongnu.org, luonengjun@huawei.com, mjt@tls.msk.ru,
qemu-devel@nongnu.org, peter.huangpeng@huawei.com,
arei.gonglei@huawei.com, pbonzini@redhat.com
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 2/4] os-posix: report error message when lock file failed
Date: Wed, 01 Oct 2014 14:38:47 +0200 [thread overview]
Message-ID: <874mvo55ig.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <BLU437-SMTP81261859A1DAABEEDAA9499FB80@phx.gbl> (Gonglei's message of "Wed, 1 Oct 2014 19:58:08 +0800")
Gonglei <arei.gonglei@hotmail.com> writes:
>> Subject: Re: [Qemu-devel] [PATCH 2/4] os-posix: report error message when
>> lock file failed
>>
>> Gonglei <arei.gonglei@hotmail.com> writes:
>>
>> > Hi,
>> >
>> >> Subject: Re: [Qemu-devel] [PATCH 2/4] os-posix: report error message when
>> >> lock file failed
>> >>
>> >> <arei.gonglei@huawei.com> writes:
>> >>
>> >> > From: Gonglei <arei.gonglei@huawei.com>
>> >> >
>> >> > It will cause that create vm failed When manager
>> >> > tool is killed forcibly (kill -9 libvirtd_pid),
>> >> > the file not was unlink, and unlock. It's better
>> >> > that report the error message for users.
>> >> >
>> >> > Signed-off-by: Huangweidong <weidong.huang@huawei.com>
>> >> > Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>> >> > ---
>> >> > os-posix.c | 1 +
>> >> > 1 file changed, 1 insertion(+)
>> >> >
>> >> > diff --git a/os-posix.c b/os-posix.c
>> >> > index 9d5ae70..89831dc 100644
>> >> > --- a/os-posix.c
>> >> > +++ b/os-posix.c
>> >> > @@ -316,6 +316,7 @@ int qemu_create_pidfile(const char *filename)
>> >> > return -1;
>> >> > }
>> >> > if (lockf(fd, F_TLOCK, 0) == -1) {
>> >> > + error_report("lock file '%s' failed: %s", filename,
>> strerror(errno));
>> >> > close(fd);
>> >> > return -1;
>> >> > }
>> >>
>> >> Only called from main():
>> >>
>> > Yes, indeed.
>> >
>> >> if (pid_file && qemu_create_pidfile(pid_file) != 0) {
>> >> os_pidfile_error();
>> >> exit(1);
>> >> }
>> >>
>> >> I suspect the error reporting is os_pidfile_error()'s job. And it
>> >> actually does it (POSIX version shown, W32 is simpler):
>> >>
>> >> void os_pidfile_error(void)
>> >> {
>> >> if (daemonize) {
>> >> uint8_t status = 1;
>> >> if (write(fds[1], &status, 1) != 1) {
>> >> perror("daemonize. Writing to pipe\n");
>> >> }
>> >> } else
>> >> fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
>> >> }
>> >>
>> >> Are you sure your patch makes sense?
>> >
>> > Yes, I'm sure it make sense. And I had tested, the result is OK as expected.
>> >
>> > When daemonize variable is true, the os_pidfile_error() usually don't
>> > report an error,
>> > because "if (write(fds[1], &status, 1) != 1)" is always false. On the other
>> > hand, we should assure that we can get the original error message
>> > when lock failed but not other information, such as "Could not acquire
>> > pid file...".
>>
>> Even if the new error message makes sense, reporting errors in two
>> places doesn't.
>>
>> qemu_create_pidfile() is designed to leave the actual error reporting to
>> its caller, which delegates it to os_pidfile_error().
>>
>> If daemonize, os_pidfile_error() signals the failure to the parent
>> process instead of reporting to stderr. The parent does the reporting,
>> in os_daemonize(). If this isn't good enough, you're certainly welcome
>> to improve it.
>>
>> Just noticed that commit e5048d1 "os-posix: report error message when
>> lock file failed" already messed this up: error reporting is spread over
>> three places: qemu_create_pidfile(), os_pidfile_error() and
>> os_daemonize().
>>
>> Please pick one method to report errors: either just in
>> qemu_create_pidfile(), or in os_pidfile_error() (normal case) and
>> os_daemonize() (if daemonize). I don't particularly care which one you
>> pick, as long as it works with and without -daemonize.
>
> If we can get the root reason of one error easier, why not?
> (I encountered the scenario described in commit message,
> I only repeated that issue and eventually got the root reason is locking
> pid file failed)
>
> I don't think it is a problem that reporting errors over
> two or three places.
>
> And I often encounter this coding style:
>
> Int funA() {
> ...
> Printf(".....");
> Return -1;
> }
>
> Int funcB() {
> If (funA() < 0) {
> Printf("something wrong\n");
> Return -1;
> }
> }
Just because you see this often doesn't make it good code. It produces
two error messages rather than one. One of them is usually useless.
WARNING: multiple messages have this Message-ID (diff)
From: Markus Armbruster <armbru@redhat.com>
To: Gonglei <arei.gonglei@hotmail.com>
Cc: peter.maydell@linaro.org, weidong.huang@huawei.com,
qemu-trivial@nongnu.org, luonengjun@huawei.com, mjt@tls.msk.ru,
qemu-devel@nongnu.org, peter.huangpeng@huawei.com,
arei.gonglei@huawei.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH 2/4] os-posix: report error message when lock file failed
Date: Wed, 01 Oct 2014 14:38:47 +0200 [thread overview]
Message-ID: <874mvo55ig.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <BLU437-SMTP81261859A1DAABEEDAA9499FB80@phx.gbl> (Gonglei's message of "Wed, 1 Oct 2014 19:58:08 +0800")
Gonglei <arei.gonglei@hotmail.com> writes:
>> Subject: Re: [Qemu-devel] [PATCH 2/4] os-posix: report error message when
>> lock file failed
>>
>> Gonglei <arei.gonglei@hotmail.com> writes:
>>
>> > Hi,
>> >
>> >> Subject: Re: [Qemu-devel] [PATCH 2/4] os-posix: report error message when
>> >> lock file failed
>> >>
>> >> <arei.gonglei@huawei.com> writes:
>> >>
>> >> > From: Gonglei <arei.gonglei@huawei.com>
>> >> >
>> >> > It will cause that create vm failed When manager
>> >> > tool is killed forcibly (kill -9 libvirtd_pid),
>> >> > the file not was unlink, and unlock. It's better
>> >> > that report the error message for users.
>> >> >
>> >> > Signed-off-by: Huangweidong <weidong.huang@huawei.com>
>> >> > Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>> >> > ---
>> >> > os-posix.c | 1 +
>> >> > 1 file changed, 1 insertion(+)
>> >> >
>> >> > diff --git a/os-posix.c b/os-posix.c
>> >> > index 9d5ae70..89831dc 100644
>> >> > --- a/os-posix.c
>> >> > +++ b/os-posix.c
>> >> > @@ -316,6 +316,7 @@ int qemu_create_pidfile(const char *filename)
>> >> > return -1;
>> >> > }
>> >> > if (lockf(fd, F_TLOCK, 0) == -1) {
>> >> > + error_report("lock file '%s' failed: %s", filename,
>> strerror(errno));
>> >> > close(fd);
>> >> > return -1;
>> >> > }
>> >>
>> >> Only called from main():
>> >>
>> > Yes, indeed.
>> >
>> >> if (pid_file && qemu_create_pidfile(pid_file) != 0) {
>> >> os_pidfile_error();
>> >> exit(1);
>> >> }
>> >>
>> >> I suspect the error reporting is os_pidfile_error()'s job. And it
>> >> actually does it (POSIX version shown, W32 is simpler):
>> >>
>> >> void os_pidfile_error(void)
>> >> {
>> >> if (daemonize) {
>> >> uint8_t status = 1;
>> >> if (write(fds[1], &status, 1) != 1) {
>> >> perror("daemonize. Writing to pipe\n");
>> >> }
>> >> } else
>> >> fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
>> >> }
>> >>
>> >> Are you sure your patch makes sense?
>> >
>> > Yes, I'm sure it make sense. And I had tested, the result is OK as expected.
>> >
>> > When daemonize variable is true, the os_pidfile_error() usually don't
>> > report an error,
>> > because "if (write(fds[1], &status, 1) != 1)" is always false. On the other
>> > hand, we should assure that we can get the original error message
>> > when lock failed but not other information, such as "Could not acquire
>> > pid file...".
>>
>> Even if the new error message makes sense, reporting errors in two
>> places doesn't.
>>
>> qemu_create_pidfile() is designed to leave the actual error reporting to
>> its caller, which delegates it to os_pidfile_error().
>>
>> If daemonize, os_pidfile_error() signals the failure to the parent
>> process instead of reporting to stderr. The parent does the reporting,
>> in os_daemonize(). If this isn't good enough, you're certainly welcome
>> to improve it.
>>
>> Just noticed that commit e5048d1 "os-posix: report error message when
>> lock file failed" already messed this up: error reporting is spread over
>> three places: qemu_create_pidfile(), os_pidfile_error() and
>> os_daemonize().
>>
>> Please pick one method to report errors: either just in
>> qemu_create_pidfile(), or in os_pidfile_error() (normal case) and
>> os_daemonize() (if daemonize). I don't particularly care which one you
>> pick, as long as it works with and without -daemonize.
>
> If we can get the root reason of one error easier, why not?
> (I encountered the scenario described in commit message,
> I only repeated that issue and eventually got the root reason is locking
> pid file failed)
>
> I don't think it is a problem that reporting errors over
> two or three places.
>
> And I often encounter this coding style:
>
> Int funA() {
> ...
> Printf(".....");
> Return -1;
> }
>
> Int funcB() {
> If (funA() < 0) {
> Printf("something wrong\n");
> Return -1;
> }
> }
Just because you see this often doesn't make it good code. It produces
two error messages rather than one. One of them is usually useless.
next prev parent reply other threads:[~2014-10-01 12:39 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-25 9:46 [Qemu-trivial] [PATCH 0/4] os: convert fprintf/perror to error_report arei.gonglei
2014-09-25 9:46 ` [Qemu-devel] " arei.gonglei
2014-09-25 9:46 ` [Qemu-trivial] [PATCH 1/4] os-posix/win32: " arei.gonglei
2014-09-25 9:46 ` [Qemu-devel] " arei.gonglei
2014-09-25 12:33 ` [Qemu-trivial] " Eric Blake
2014-09-25 12:33 ` Eric Blake
2014-09-25 12:53 ` [Qemu-trivial] " Gonglei (Arei)
2014-09-25 12:53 ` Gonglei (Arei)
2014-09-25 9:46 ` [Qemu-trivial] [PATCH 2/4] os-posix: report error message when lock file failed arei.gonglei
2014-09-25 9:46 ` [Qemu-devel] " arei.gonglei
2014-10-01 8:45 ` [Qemu-trivial] " Markus Armbruster
2014-10-01 8:45 ` Markus Armbruster
2014-10-01 9:12 ` [Qemu-trivial] " Gonglei
2014-10-01 9:12 ` Gonglei
2014-10-01 10:24 ` [Qemu-trivial] " Markus Armbruster
2014-10-01 10:24 ` Markus Armbruster
2014-10-01 11:58 ` [Qemu-trivial] " Gonglei
2014-10-01 11:58 ` Gonglei
2014-10-01 12:38 ` Markus Armbruster [this message]
2014-10-01 12:38 ` Markus Armbruster
2014-10-24 7:32 ` [Qemu-trivial] " Michael Tokarev
2014-10-24 7:32 ` [Qemu-devel] " Michael Tokarev
2014-10-24 8:56 ` Gonglei
2014-10-24 8:56 ` [Qemu-devel] " Gonglei
2014-09-25 9:46 ` [Qemu-trivial] [PATCH 3/4] osdep: convert fprintf to error_report arei.gonglei
2014-09-25 9:46 ` [Qemu-devel] " arei.gonglei
2014-09-25 12:35 ` [Qemu-trivial] " Eric Blake
2014-09-25 12:35 ` Eric Blake
2014-09-25 12:54 ` [Qemu-trivial] " Gonglei (Arei)
2014-09-25 12:54 ` Gonglei (Arei)
2014-09-25 9:46 ` [Qemu-trivial] [PATCH 4/4] oslib-posix/win32: convert fprintf/perror " arei.gonglei
2014-09-25 9:46 ` [Qemu-devel] " arei.gonglei
2014-09-25 12:36 ` [Qemu-trivial] " Eric Blake
2014-09-25 12:36 ` Eric Blake
2014-09-25 12:55 ` [Qemu-trivial] " Gonglei (Arei)
2014-09-25 12:55 ` Gonglei (Arei)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874mvo55ig.fsf@blackfin.pond.sub.org \
--to=armbru@redhat.com \
--cc=arei.gonglei@hotmail.com \
--cc=arei.gonglei@huawei.com \
--cc=luonengjun@huawei.com \
--cc=mjt@tls.msk.ru \
--cc=pbonzini@redhat.com \
--cc=peter.huangpeng@huawei.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=weidong.huang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.