From: Ian Jackson <ian.jackson@eu.citrix.com>
To: Wei Liu <wei.liu2@citrix.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: Re: [PATCH 2/6] xenconsoled: switch hypervisor log to use logfile abstraction
Date: Fri, 8 Jul 2016 17:58:52 +0100 [thread overview]
Message-ID: <22399.56268.45784.636511@mariner.uk.xensource.com> (raw)
In-Reply-To: <1465228781-22754-3-git-send-email-wei.liu2@citrix.com>
Wei Liu writes ("[PATCH 2/6] xenconsoled: switch hypervisor log to use logfile abstraction"):
> To minimise code churn, copy and paste a some existing functions and
> adapt them to write to logfile. The functions to deal with fd directly
> will go away eventually.
...
> +static int write_logfile(struct logfile *logfile, const char *buf,
> + size_t len)
> +{
> + ssize_t r = logfile_append(logfile, buf, len);
> +
> + if (r < 0) return -1;
> + return 0;
> +}
That this is necessary suggests that logfile_append has an
inconvenient calling convention.
> +static int write_logfile_with_timestamp(struct logfile *logfile,
> + const char *data, size_t sz,
> + int *needts)
> +{
This should be in logfile.c. Furthermore, this is at the wrong level
with respect to log rotation:
> + if ((*needts && logfile_append(logfile, ts, tslen))
This could result in a timestamp being split across two different
logfiles which is undesirable. So I think this needs to be done at
the layer below.
> + data = nl + 1;
> + if (found_nl) {
> + // If we printed a newline, strip all \r following it
> + while (data <= last_byte && *data == '\r')
> + data++;
> + }
I would prefer that we only apply a lossless transformation to
logfiles, even if that means that our lotfiles contain CRs. Also,
this is rather odd. Surely it is more usual for the CR to precede the
LF.
I suggest the transformation `after every LF, preface the next byte
with the timestamp of that next byte'.
> - if (fd != -1 && log_time_hv) {
> - if (write_with_timestamp(fd, "Logfile Opened\n",
> - strlen("Logfile Opened\n"),
> - &log_time_hv_needts) < 0) {
> +
> + if (tmp && log_time_hv) {
> + if (write_logfile_with_timestamp(tmp, "Logfile Opened\n",
> + strlen("Logfile Opened\n"),
> + &log_time_hv_needts) < 0) {
I think that if timestamps are turned off, writing the "Logfile
Opened" (with no preceding timestamp) is probably a good idea. So
this can be made simpler.
> if (log_hv) {
> - if (log_hv_fd != -1)
> - close(log_hv_fd);
> - log_hv_fd = create_hv_log();
> + if (log_hv_file)
> + logfile_free(log_hv_file);
> + log_hv_file = create_hv_log();
You could separate out the nonfunctional changes if you did it in
stages:
* provide logfile_valid as a dummy macro that tests against -1
* replace `log_hv_fd' with `log_hv' throughout; replace
comparisons with -1 with logfile_valid(log_hv); likewise
client logfiles - no functional change
* replace log opening code with calls to logfile_open; change
types; change implementation of logfile_valid
Ian.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-07-08 16:59 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-06 15:59 [PATCH 0/6] xenconsoled: rotating log file abstration Wei Liu
2016-06-06 15:59 ` [PATCH 1/6] xenconsoled: introduce log file abstraction Wei Liu
2016-07-08 16:50 ` Ian Jackson
2016-06-06 15:59 ` [PATCH 2/6] xenconsoled: switch hypervisor log to use logfile abstraction Wei Liu
2016-07-08 16:58 ` Ian Jackson [this message]
2016-06-06 15:59 ` [PATCH 3/6] xenconsoled: switch guest " Wei Liu
2016-07-08 17:01 ` Ian Jackson
2016-06-06 15:59 ` [PATCH 4/6] xenconsoled: delete two now unused functions Wei Liu
2016-07-08 17:01 ` Ian Jackson
2016-06-06 15:59 ` [PATCH 5/6] xenconsoled: options to control log rotation Wei Liu
2016-07-08 17:02 ` Ian Jackson
2016-06-06 15:59 ` [PATCH 6/6] xenconsoled: handle --log-backups 0 in logfile_rollover Wei Liu
2016-07-08 17:03 ` Ian Jackson
2016-06-06 20:40 ` [PATCH 0/6] xenconsoled: rotating log file abstration Doug Goldstein
2016-06-07 8:07 ` Wei Liu
2016-06-07 9:44 ` David Vrabel
2016-06-07 9:55 ` Wei Liu
2016-06-07 10:17 ` David Vrabel
2016-06-07 10:21 ` Wei Liu
2016-06-07 10:29 ` David Vrabel
2016-06-07 10:34 ` Wei Liu
2016-06-07 10:35 ` David Vrabel
2016-06-07 10:43 ` Wei Liu
2016-07-02 10:24 ` Wei Liu
2016-07-04 17:07 ` Ian Jackson
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=22399.56268.45784.636511@mariner.uk.xensource.com \
--to=ian.jackson@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).