From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Wei Liu <wei.liu2@citrix.com>, Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: [PATCH 3/6] xenconsoled: switch guest log to use logfile abstraction
Date: Mon, 6 Jun 2016 16:59:38 +0100 [thread overview]
Message-ID: <1465228781-22754-4-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1465228781-22754-1-git-send-email-wei.liu2@citrix.com>
Note that this causes write_with_timestamp to have no caller. Mark
it as unused for now to minimise code churn.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
tools/console/daemon/io.c | 67 +++++++++++++++++++++++++----------------------
1 file changed, 35 insertions(+), 32 deletions(-)
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index 228c4af..c2f63e6 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -95,7 +95,7 @@ struct domain {
int master_fd;
int master_pollfd_idx;
int slave_fd;
- int log_fd;
+ struct logfile *log;
bool is_dead;
unsigned last_seen;
struct buffer buffer;
@@ -137,8 +137,9 @@ static int write_logfile(struct logfile *logfile, const char *buf,
return 0;
}
-static int write_with_timestamp(int fd, const char *data, size_t sz,
- int *needts)
+static __attribute__((unused))
+int write_with_timestamp(int fd, const char *data, size_t sz,
+ int *needts)
{
char ts[32];
time_t now = time(NULL);
@@ -235,16 +236,16 @@ static void buffer_append(struct domain *dom)
* no one is listening on the console pty then it will fill up
* and handle_tty_write will stop being called.
*/
- if (dom->log_fd != -1) {
+ if (dom->log) {
int logret;
if (log_time_guest) {
- logret = write_with_timestamp(
- dom->log_fd,
+ logret = write_logfile_with_timestamp(
+ dom->log,
buffer->data + buffer->size - size,
size, &log_time_guest_needts);
} else {
- logret = write_all(
- dom->log_fd,
+ logret = write_logfile(
+ dom->log,
buffer->data + buffer->size - size,
size);
}
@@ -336,50 +337,53 @@ static struct logfile *create_hv_log(void)
return tmp;
}
-static int create_domain_log(struct domain *dom)
+static struct logfile *create_domain_log(struct domain *dom)
{
char logfile[PATH_MAX];
char *namepath, *data, *s;
- int fd;
unsigned int len;
+ struct logfile *tmp;
namepath = xs_get_domain_path(xs, dom->domid);
s = realloc(namepath, strlen(namepath) + 6);
if (s == NULL) {
free(namepath);
- return -1;
+ return NULL;
}
namepath = s;
strcat(namepath, "/name");
data = xs_read(xs, XBT_NULL, namepath, &len);
free(namepath);
if (!data)
- return -1;
+ return NULL;
if (!len) {
free(data);
- return -1;
+ return NULL;
}
snprintf(logfile, PATH_MAX-1, "%s/guest-%s.log", log_dir, data);
free(data);
logfile[PATH_MAX-1] = '\0';
- fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0644);
- if (fd == -1)
+ tmp = logfile_new(logfile, 0644);
+
+ if (!tmp)
dolog(LOG_ERR, "Failed to open log %s: %d (%s)",
logfile, errno, strerror(errno));
- if (fd != -1 && log_time_guest) {
- if (write_with_timestamp(fd, "Logfile Opened\n",
- strlen("Logfile Opened\n"),
- &log_time_guest_needts) < 0) {
+
+ if (tmp && log_time_guest) {
+ if (write_logfile_with_timestamp(tmp, "Logfile Opened\n",
+ strlen("Logfile Opened\n"),
+ &log_time_guest_needts) < 0) {
dolog(LOG_ERR, "Failed to log opening timestamp "
- "in %s: %d (%s)", logfile, errno,
+ "in %s: %d (%s)", tmp->basepath, errno,
strerror(errno));
- close(fd);
- return -1;
+ logfile_free(tmp);
+ return NULL;
}
}
- return fd;
+
+ return tmp;
}
static void domain_close_tty(struct domain *dom)
@@ -665,8 +669,8 @@ static int domain_create_ring(struct domain *dom)
}
}
- if (log_guest && (dom->log_fd == -1))
- dom->log_fd = create_domain_log(dom);
+ if (log_guest && !dom->log)
+ dom->log = create_domain_log(dom);
out:
return err;
@@ -724,7 +728,6 @@ static struct domain *create_domain(int domid)
dom->master_fd = -1;
dom->master_pollfd_idx = -1;
dom->slave_fd = -1;
- dom->log_fd = -1;
dom->xce_pollfd_idx = -1;
dom->next_period = ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) + RATE_LIMIT_PERIOD;
@@ -777,9 +780,9 @@ static void cleanup_domain(struct domain *d)
{
domain_close_tty(d);
- if (d->log_fd != -1) {
- close(d->log_fd);
- d->log_fd = -1;
+ if (d->log) {
+ logfile_free(d->log);
+ d->log = NULL;
}
free(d->buffer.data);
@@ -995,9 +998,9 @@ static void handle_log_reload(void)
if (log_guest) {
struct domain *d;
for (d = dom_head; d; d = d->next) {
- if (d->log_fd != -1)
- close(d->log_fd);
- d->log_fd = create_domain_log(d);
+ if (d->log)
+ logfile_free(d->log);
+ d->log = create_domain_log(d);
}
}
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-06-06 15: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
2016-06-06 15:59 ` Wei Liu [this message]
2016-07-08 17:01 ` [PATCH 3/6] xenconsoled: switch guest " 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=1465228781-22754-4-git-send-email-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=Ian.Jackson@eu.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).