Skip to contentSkip to conversation

xl: Add "xl uptime" command

PATCH In review Yang Hongyang 2 participants 6 messages May 13, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xl: Add "xl uptime" command

Add "xl uptime" command, a clone of "xm uptime".

tools/libxl/libxl.c +20 -0
diff -r d77a88f938c6 tools/libxl/libxl.c
@@ -2629,3 +2629,23 @@
 
     return rc;
 }
+
+unsigned long libxl_get_start_time(struct libxl_ctx *ctx, uint32_t domid)
+{
+    char *dompath = libxl_xs_get_dompath(ctx, domid);
+    unsigned long s_time = 0;
+    char *start_time = NULL;
+    char *vm_path = NULL;
+
+    vm_path = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/vm", dompath));
+    start_time = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/start_time", vm_path));
+    if (start_time == NULL) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, -1,
+            "Can't get start time of domain '%d'", domid);
+        return -1;
+    }
+    s_time = strtoul(start_time, NULL, 10);
+
+    return s_time;
+}
+
tools/libxl/libxl.h +1 -0
diff -r d77a88f938c6 tools/libxl/libxl.h
@@ -481,5 +481,6 @@
                                   struct libxl_sched_credit *scinfo);
 int libxl_send_trigger(struct libxl_ctx *ctx, uint32_t domid,
                        char *trigger_name, uint32_t vcpuid);
+unsigned long libxl_get_start_time(struct libxl_ctx *ctx, uint32_t domid);
 #endif /* LIBXL_H */
 
tools/libxl/xl_cmdimpl.c +157 -0

160 lines not on this page · raw message

tools/libxl/xl_cmdimpl.h +1 -0
diff -r d77a88f938c6 tools/libxl/xl_cmdimpl.h
@@ -39,5 +39,6 @@
 int main_domname(int argc, char **argv);
 int main_rename(int argc, char **argv);
 int main_trigger(int argc, char **argv);
+int main_uptime(int argc, char **argv);
 
 void help(char *command);
tools/libxl/xl_cmdtable.c +5 -0
diff -r d77a88f938c6 tools/libxl/xl_cmdtable.c
@@ -172,6 +172,11 @@
       "Send a trigger to a domain",
       "<Domain> <nmi|reset|init|power|sleep> [<VCPU>]",
     },
+    { "uptime",
+      &main_uptime,
+      "Print uptime for all/some domains",
+      "[-s] [Domain ...]",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 2 lines
Regards
Yang Hongyang
#1 lore raw
Quoted 20 lines · Yang Hongyang

Add "xl uptime" command, a clone of "xm uptime".

diff -r d77a88f938c6 tools/libxl/libxl.c

tools/libxl/libxl.c +9 -0
@@ -2629,3 +2629,23 @@
 
      return rc;
  }
+
+unsigned long libxl_get_start_time(struct libxl_ctx *ctx, uint32_t domid)
+{
+    char *dompath = libxl_xs_get_dompath(ctx, domid);
+    unsigned long s_time = 0;
+    char *start_time = NULL;
+    char *vm_path = NULL;
+
+    vm_path = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/vm", dompath));

tools/libxl/libxl.c line 2650

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+    start_time = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/start_time", vm_path));
+    if (start_time == NULL) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, -1,
+            "Can't get start time of domain '%d'", domid);
+        return -1;
+    }
+    s_time = strtoul(start_time, NULL, 10);
+
+    return s_time;
+}

this function should more than likely return a uint64_t or a uint32_t, but certainly not an unsigned long. and since it apply to a domain it should be call libxl_domain_get_start_time.

I find this command basically useless, since on restore the "start_time" is not kept. do we actually need this ?

Signature · 1 line
Vincent
#2 lore raw

Hi Vincent,

Quoted 30 lines · Vincent Hanquez
Quoted 29 lines · Yang Hongyang

Add "xl uptime" command, a clone of "xm uptime".

diff -r d77a88f938c6 tools/libxl/libxl.c

tools/libxl/libxl.c Fri May 14 01:25:56 2010 +0800 renamed from tools/libxl/libxl.c Tue May 11 14:05:28 2010 +0100 +2 -0
@@ -2629,3 +2629,23 @@
 
      return rc;
  }
+
+unsigned long libxl_get_start_time(struct libxl_ctx *ctx, uint32_t

domid)

tools/libxl/libxl.c Fri May 14 01:25:56 2010 +0800 renamed from tools/libxl/libxl.c Tue May 11 14:05:28 2010 +0100 +7 -0
+{
+    char *dompath = libxl_xs_get_dompath(ctx, domid);
+    unsigned long s_time = 0;
+    char *start_time = NULL;
+    char *vm_path = NULL;
+
+    vm_path = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx,

"%s/vm", dompath));
+ start_time = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx,
"%s/start_time", vm_path));

tools/libxl/libxl.c Fri May 14 01:25:56 2010 +0800 renamed from tools/libxl/libxl.c Tue May 11 14:05:28 2010 +0100 +5 -0
+    if (start_time == NULL) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, -1,
+            "Can't get start time of domain '%d'", domid);
+        return -1;
+    }
Quoted 8 lines

tools/libxl/libxl.c Fri May 14 01:25:56 2010 +0800

Quoted 4 lines
tools/libxl/libxl.c Fri May 14 01:25:56 2010 +0800 renamed from tools/libxl/libxl.c Tue May 11 14:05:28 2010 +0100 +4 -0
+    s_time = strtoul(start_time, NULL, 10);
+
+    return s_time;
+}

this function should more than likely return a uint64_t or a uint32_t, but certainly not an unsigned long. and since it apply to a domain it should be call libxl_domain_get_start_time.

Thank you for your review,I'll fix that.

Quoted 4 lines

I find this command basically useless, since on restore the "start_time" is not kept. do we actually need this ?

I think it's sometimes useful. I noticed that just the day before yesterday, somebody asked in the xen-api list about "uptime" command.

-------- Original Message --------
Subject: [Xen-API] Want to find out the uptime of individual VM running
on Citrix Xen
Date: Tue, 11 May 2010 04:00:13 -0600
From: Sane, Abhijeet <[email protected]>
To: [email protected] <[email protected]>

Hi,

I want to know if it is possible to get the uptime of individual VM that are running on the Citrix host using the Citrix Xen python API..

Something on the lines of ‘xm uptime’

Regards

Abhijeet Sane

Signature · 2 lines
Regards
Yang Hongyang
#3 lore raw
Quoted 6 lines · Yang Hongyang
Quoted 3 lines

I find this command basically useless, since on restore the "start_time" is not kept. do we actually need this ?

I think it's sometimes useful. I noticed that just the day before yesterday, somebody asked in the xen-api list about "uptime" command.

it is useful if it works :)

however this version of start_time means "when was this xen domain started" which is not the VM start time (i.e. "when was my vm booted"). To be useful start_time need to preserved across migration and suspend/restore.

xen-api does the right thing and returns the later.

Signature · 1 line
Vincent
#5 lore raw
In reply to Yang Hongyang

v1->v2:
1.libxl_get_start_time() is apply to a vm so use libxl_vm_get_start_time instead. 2.replace unsigned long with uint32_t.

===========================================================================

Add "xl uptime" command, a clone of "xm uptime".

tools/libxl/libxl.c +20 -0
diff -r d77a88f938c6 tools/libxl/libxl.c
@@ -2629,3 +2629,23 @@
 
     return rc;
 }
+
+uint32_t libxl_vm_get_start_time(struct libxl_ctx *ctx, uint32_t domid)
+{
+    char *dompath = libxl_xs_get_dompath(ctx, domid);
+    unsigned long s_time = 0;
+    char *start_time = NULL;
+    char *vm_path = NULL;
+
+    vm_path = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/vm", dompath));
+    start_time = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/start_time", vm_path));
+    if (start_time == NULL) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, -1,
+            "Can't get start time of domain '%d'", domid);
+        return -1;
+    }
+    s_time = strtoul(start_time, NULL, 10);
+
+    return s_time;
+}
+
tools/libxl/libxl.h +1 -0
diff -r d77a88f938c6 tools/libxl/libxl.h
@@ -481,5 +481,6 @@
                                   struct libxl_sched_credit *scinfo);
 int libxl_send_trigger(struct libxl_ctx *ctx, uint32_t domid,
                        char *trigger_name, uint32_t vcpuid);
+uint32_t libxl_vm_get_start_time(struct libxl_ctx *ctx, uint32_t domid);
 #endif /* LIBXL_H */
 
tools/libxl/xl_cmdimpl.c +157 -0

160 lines not on this page · raw message

tools/libxl/xl_cmdimpl.h +1 -0
diff -r d77a88f938c6 tools/libxl/xl_cmdimpl.h
@@ -39,5 +39,6 @@
 int main_domname(int argc, char **argv);
 int main_rename(int argc, char **argv);
 int main_trigger(int argc, char **argv);
+int main_uptime(int argc, char **argv);
 
 void help(char *command);
tools/libxl/xl_cmdtable.c +5 -0
diff -r d77a88f938c6 tools/libxl/xl_cmdtable.c
@@ -172,6 +172,11 @@
       "Send a trigger to a domain",
       "<Domain> <nmi|reset|init|power|sleep> [<VCPU>]",
     },
+    { "uptime",
+      &main_uptime,
+      "Print uptime for all/some domains",
+      "[-s] [Domain]",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 2 lines
Regards
Yang Hongyang
#4 lore raw
In reply to Vincent Hanquez
Quoted 9 lines · Vincent Hanquez
Quoted 7 lines · Yang Hongyang
Quoted 3 lines

I find this command basically useless, since on restore the "start_time" is not kept. do we actually need this ?

I think it's sometimes useful. I noticed that just the day before yesterday,
somebody asked in the xen-api list about "uptime" command.

Quoted 9 lines

it is useful if it works :)

however this version of start_time means "when was this xen domain started" which is not the VM start time (i.e. "when was my vm booted"). To be useful start_time need to preserved across migration and suspend/restore.

xen-api does the right thing and returns the later.

So more work has to be done to get xl exactly right as xen-api.:)

And I noticed that if use xl create, start_time will not be set. xm create will set the start_time properly, I wonder if it is xend that set the start_time or is this a bug?

Signature · 2 lines
Regards
Yang Hongyang