Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 314215 Details for
Bug 458968
[RHEL5.3]: Make libvirt understand new expanded xvd devices in guests
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Updated libvirt expand vbd patch
libvirt-0.3.3-expanded-stats-3.patch (text/plain), 10.77 KB, created by
Chris Lalancette
on 2008-08-13 15:26:08 UTC
(
hide
)
Description:
Updated libvirt expand vbd patch
Filename:
MIME Type:
Creator:
Chris Lalancette
Created:
2008-08-13 15:26:08 UTC
Size:
10.77 KB
patch
obsolete
>diff -urp libvirt-0.3.3.orig/src/internal.h libvirt-0.3.3/src/internal.h >--- libvirt-0.3.3.orig/src/internal.h 2008-08-13 11:04:02.000000000 -0400 >+++ libvirt-0.3.3/src/internal.h 2008-08-13 11:04:25.000000000 -0400 >@@ -34,6 +34,7 @@ extern "C" { > #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0) > #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0) > #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0) >+#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) > > #ifndef __GNUC__ > #define __FUNCTION__ __func__ >diff -urp libvirt-0.3.3.orig/src/stats_linux.c libvirt-0.3.3/src/stats_linux.c >--- libvirt-0.3.3.orig/src/stats_linux.c 2008-08-13 11:04:02.000000000 -0400 >+++ libvirt-0.3.3/src/stats_linux.c 2008-08-13 11:16:24.000000000 -0400 >@@ -13,15 +13,18 @@ > /* This file only applies on Linux. */ > #ifdef __linux__ > >+#define _GNU_SOURCE > #include <stdio.h> > #include <stdlib.h> > #include <fcntl.h> > #include <string.h> > #include <unistd.h> >+#include <regex.h> > > #include <xs.h> > > #include "internal.h" >+#include "util.h" > #include "xen_unified.h" > #include "stats_linux.h" > >@@ -219,60 +222,148 @@ read_bd_stats (virConnectPtr conn, xenUn > return 0; > } > >-int >-xenLinuxDomainBlockStats (xenUnifiedPrivatePtr priv, >- virDomainPtr dom, >- const char *path, >- struct _virDomainBlockStats *stats) >+static int >+disk_re_match(const char *regex, const char *path, int *part) > { >- int minor, device; >+ regex_t myreg; >+ int err; >+ int retval; >+ regmatch_t pmatch[3]; > >- /* Paravirt domains: >- * Paths have the form "xvd[a-]" and map to paths >- * /sys/devices/xen-backend/(vbd|tap)-domid-major:minor/ >- * statistics/(rd|wr|oo)_req. >- * The major:minor is in this case fixed as 202*256 + minor*16 >- * where minor is 0 for xvda, 1 for xvdb and so on. >- * >- * XXX Not clear what happens to device numbers for devices >- * >= xdvo (minor >= 16), which would otherwise overflow the >- * 256 minor numbers assigned to this major number. So we >- * currently limit you to the first 16 block devices per domain. >- */ >- if (strlen (path) == 4 && >- STREQLEN (path, "xvd", 3)) { >- if ((minor = path[3] - 'a') < 0 || minor >= 16) { >- statsErrorFunc (dom->conn, VIR_ERR_INVALID_ARG, __FUNCTION__, >- "invalid path, should be xvda, xvdb, etc.", >- dom->id); >- return -1; >- } >- device = XENVBD_MAJOR * 256 + minor * 16; >+ retval = 0; >+ >+ err = regcomp(&myreg, regex, REG_EXTENDED); >+ if (err != 0) >+ return 0; >+ >+ err = regexec(&myreg, path, 3, pmatch, 0); > >- return read_bd_stats (dom->conn, priv, device, dom->id, stats); >+ if (err == 0) { >+ /* OK, we have a match; see if we have a partition */ >+ *part = 0; >+ retval = 1; >+ if (pmatch[1].rm_so != -1) { >+ if (virStrToLong_i(path + pmatch[1].rm_so, NULL, 10, part) < 0) >+ retval = 0; >+ } > } >- /* Fullvirt domains: >- * hda, hdb etc map to major = HD_MAJOR*256 + minor*16. >+ >+ regfree(&myreg); >+ >+ return retval; >+} >+ >+int >+xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *path) >+{ >+ int major, minor; >+ int part; >+ int retval; >+ char *mod_path; >+ >+ int const scsi_majors[] = { SCSI_DISK0_MAJOR, SCSI_DISK1_MAJOR, >+ SCSI_DISK2_MAJOR, SCSI_DISK3_MAJOR, >+ SCSI_DISK4_MAJOR, SCSI_DISK5_MAJOR, >+ SCSI_DISK6_MAJOR, SCSI_DISK7_MAJOR, >+ SCSI_DISK8_MAJOR, SCSI_DISK9_MAJOR, >+ SCSI_DISK10_MAJOR, SCSI_DISK11_MAJOR, >+ SCSI_DISK12_MAJOR, SCSI_DISK13_MAJOR, >+ SCSI_DISK14_MAJOR, SCSI_DISK15_MAJOR }; >+ int const ide_majors[] = { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR, >+ IDE4_MAJOR, IDE5_MAJOR, IDE6_MAJOR, IDE7_MAJOR, >+ IDE8_MAJOR, IDE9_MAJOR }; >+ >+ /* >+ * Possible block device majors & partition ranges. This >+ * matches the ranges supported in Xend xen/util/blkif.py >+ * >+ * hdNM: N=a-t, M=1-63, major={IDE0_MAJOR -> IDE9_MAJOR} >+ * sdNM: N=a-z,aa-iv, M=1-15, major={SCSI_DISK0_MAJOR -> SCSI_DISK15_MAJOR} >+ * xvdNM: N=a-p M=1-15, major=XENVBD_MAJOR >+ * xvdNM: N=q-z,aa-iz M=1-15, major=(1<<28) >+ * >+ * The path for statistics will be > * >- * See comment above about devices >= hdo. >+ * /sys/devices/xen-backend/(vbd|tap)-{domid}-{devid}/statistics/{...} > */ >- else if (strlen (path) == 3 && >- STREQLEN (path, "hd", 2)) { >- if ((minor = path[2] - 'a') < 0 || minor >= 16) { >- statsErrorFunc (dom->conn, VIR_ERR_INVALID_ARG, __FUNCTION__, >- "invalid path, should be hda, hdb, etc.", >- dom->id); >- return -1; >- } >- device = HD_MAJOR * 256 + minor * 16; > >- return read_bd_stats (dom->conn, priv, device, dom->id, stats); >+ if (strlen(path) >= 5 && STRPREFIX(path, "/dev/")) >+ retval = asprintf(&mod_path, "%s", path); >+ else >+ retval = asprintf(&mod_path, "/dev/%s", path); >+ >+ if (retval < 0) { >+ statsErrorFunc (conn, VIR_ERR_NO_MEMORY, __FUNCTION__, >+ "allocating mod_path", domid); >+ return -1; > } > >- /* Otherwise, unsupported device name. */ >- statsErrorFunc (dom->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__, >- "unsupported path (use xvda, hda, etc.)", dom->id); >- return -1; >+ retval = -1; >+ >+ if (disk_re_match("/dev/sd[a-z]([1-9]|1[0-5])?$", mod_path, &part)) { >+ major = scsi_majors[(mod_path[7] - 'a') / 16]; >+ minor = ((mod_path[7] - 'a') % 16) * 16 + part; >+ retval = major * 256 + minor; >+ } >+ else if (disk_re_match("/dev/sd[a-h][a-z]([1-9]|1[0-5])?$", >+ mod_path, &part) || >+ disk_re_match("/dev/sdi[a-v]([1-9]|1[0-5])?$", >+ mod_path, &part)) { >+ major = scsi_majors[((mod_path[7] - 'a' + 1) * 26 + (mod_path[8] - 'a')) / 16]; >+ minor = (((mod_path[7] - 'a' + 1) * 26 + (mod_path[8] - 'a')) % 16) >+ * 16 + part; >+ retval = major * 256 + minor; >+ } >+ else if (disk_re_match("/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?$", >+ mod_path, &part)) { >+ major = ide_majors[(mod_path[7] - 'a') / 2]; >+ minor = ((mod_path[7] - 'a') % 2) * 64 + part; >+ retval = major * 256 + minor; >+ } >+ else if (disk_re_match("/dev/xvd[a-p]([1-9]|1[0-5])?$", mod_path, &part)) >+ retval = (202 << 8) + ((mod_path[8] - 'a') << 4) + part; >+ else if (disk_re_match("/dev/xvd[q-z]([1-9]|1[0-5])?$", mod_path, &part)) >+ retval = (1 << 28) + ((mod_path[8] - 'a') << 8) + part; >+ else if (disk_re_match("/dev/xvd[a-i][a-z]([1-9]|1[0-5])?$", >+ mod_path, &part)) >+ retval = (1 << 28) + (((mod_path[8] - 'a' + 1) * 26 + (mod_path[9] - 'a')) << 8) + part; >+ /* >+ * OK, we've now checked the common case (things that work); check the >+ * beginning of the strings for better error messages >+ */ >+ else if (strlen(mod_path) >= 7 && STRPREFIX(mod_path, "/dev/sd")) >+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__, >+ "invalid path, device names must be in the range sda[1-15] - sdiv[1-15]", >+ domid); >+ else if (strlen(mod_path) >= 7 && STRPREFIX(mod_path, "/dev/hd")) >+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__, >+ "invalid path, device names must be in the range hda[1-63] - hdt[1-63]", >+ domid); >+ else if (strlen(mod_path) >= 8 && STRPREFIX(mod_path, "/dev/xvd")) >+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__, >+ "invalid path, device names must be in the range xvda[1-15] - xvdiz[1-15]", >+ domid); >+ else >+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__, >+ "unsupported path, use xvdN, hdN, or sdN", domid); >+ >+ free(mod_path); >+ >+ return retval; >+} >+ >+int >+xenLinuxDomainBlockStats (xenUnifiedPrivatePtr priv, >+ virDomainPtr dom, >+ const char *path, >+ struct _virDomainBlockStats *stats) >+{ >+ int device = xenLinuxDomainDeviceID(dom->conn, dom->id, path); >+ >+ if (device < 0) >+ return -1; >+ >+ return read_bd_stats (dom->conn, priv, device, dom->id, stats); > } > > #endif /* WITH_XEN */ >diff -urp libvirt-0.3.3.orig/src/stats_linux.h libvirt-0.3.3/src/stats_linux.h >--- libvirt-0.3.3.orig/src/stats_linux.h 2008-08-13 11:04:02.000000000 -0400 >+++ libvirt-0.3.3/src/stats_linux.h 2008-08-13 11:15:12.000000000 -0400 >@@ -21,6 +21,8 @@ extern int xenLinuxDomainBlockStats (xen > extern int linuxDomainInterfaceStats (virConnectPtr conn, const char *path, > struct _virDomainInterfaceStats *stats); > >+extern int xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *dev); >+ > #endif /* __linux__ */ > > #endif /* __STATS_LINUX_H__ */ >diff -urp libvirt-0.3.3.orig/src/util.c libvirt-0.3.3/src/util.c >--- libvirt-0.3.3.orig/src/util.c 2008-08-13 11:04:02.000000000 -0400 >+++ libvirt-0.3.3/src/util.c 2008-08-13 11:08:25.000000000 -0400 >@@ -226,3 +226,27 @@ ssize_t safewrite(int fd, const void *bu > } > return nwritten; > } >+ >+/* Like strtol, but produce an "int" result, and check more carefully. >+ Return 0 upon success; return -1 to indicate failure. >+ When END_PTR is NULL, the byte after the final valid digit must be NUL. >+ Otherwise, it's like strtol and lets the caller check any suffix for >+ validity. This function is careful to return -1 when the string S >+ represents a number that is not representable as an "int". */ >+int >+__virStrToLong_i(char const *s, char **end_ptr, int base, int *result) >+{ >+ long int val; >+ char *p; >+ int err; >+ >+ errno = 0; >+ val = strtol(s, &p, base); >+ err = (errno || (!end_ptr && *p) || p == s || (int) val != val); >+ if (end_ptr) >+ *end_ptr = p; >+ if (err) >+ return -1; >+ *result = val; >+ return 0; >+} >diff -urp libvirt-0.3.3.orig/src/util.h libvirt-0.3.3/src/util.h >--- libvirt-0.3.3.orig/src/util.h 2007-09-26 05:09:13.000000000 -0400 >+++ libvirt-0.3.3/src/util.h 2008-08-13 11:09:04.000000000 -0400 >@@ -26,3 +26,9 @@ int virExecNonBlock(virConnectPtr conn, > > int saferead(int fd, void *buf, size_t count); > ssize_t safewrite(int fd, const void *buf, size_t count); >+ >+int __virStrToLong_i(char const *s, >+ char **end_ptr, >+ int base, >+ int *result); >+#define virStrToLong_i(s,e,b,r) __virStrToLong_i((s),(e),(b),(r))
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 458968
:
314210
| 314215