[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] ioemu: Fixes for BSD.
# HG changeset patch # User Keir Fraser <keir@xxxxxxxxxxxxx> # Date 1190907383 -3600 # Node ID 04cc0e22a20a0bdf6ceefb016185175ee094ed30 # Parent 98d97e3ad29a9e15e6033625dbafd0538133dc36 ioemu: Fixes for BSD. Signed-off-by: Christoph Egger <Christoph.Egger@xxxxxxx> --- tools/ioemu/audio/audio.c | 4 - tools/ioemu/audio/mixeng.c | 4 + tools/ioemu/audio/ossaudio.c | 7 ++ tools/ioemu/block-raw.c | 25 ++++++++++ tools/ioemu/block-vvfat.c | 2 tools/ioemu/bswap.h | 7 ++ tools/ioemu/cutils.c | 6 +- tools/ioemu/monitor.c | 38 +++++++-------- tools/ioemu/osdep.h | 4 + tools/ioemu/target-i386-dm/exec-dm.c | 4 - tools/ioemu/usb-linux.c | 2 tools/ioemu/vl.c | 84 +++++++++++++++++++++++++++++------ tools/ioemu/vl.h | 4 - tools/ioemu/vnc.c | 3 + 14 files changed, 148 insertions(+), 46 deletions(-) diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/audio/audio.c --- a/tools/ioemu/audio/audio.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/audio/audio.c Thu Sep 27 16:36:23 2007 +0100 @@ -207,7 +207,7 @@ static char *audio_alloc_prefix (const c strcat (r, s); for (i = 0; i < len; ++i) { - u[i] = toupper (u[i]); + u[i] = toupper ((uint8_t)u[i]); } } return r; @@ -446,7 +446,7 @@ static void audio_process_options (const /* copy while upper-casing, including trailing zero */ for (i = 0; i <= preflen; ++i) { - optname[i + sizeof (qemu_prefix) - 1] = toupper (prefix[i]); + optname[i + sizeof (qemu_prefix) - 1] = toupper ((uint8_t)prefix[i]); } strcat (optname, "_"); strcat (optname, opt->name); diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/audio/mixeng.c --- a/tools/ioemu/audio/mixeng.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/audio/mixeng.c Thu Sep 27 16:36:23 2007 +0100 @@ -102,6 +102,7 @@ #undef SHIFT t_sample *mixeng_conv[2][2][2][2] = { +#ifndef _BSD { { { @@ -146,9 +147,11 @@ t_sample *mixeng_conv[2][2][2][2] = { } } } +#endif /* !_BSD */ }; f_sample *mixeng_clip[2][2][2][2] = { +#ifndef _BSD { { { @@ -193,6 +196,7 @@ f_sample *mixeng_clip[2][2][2][2] = { } } } +#endif /* !_BSD */ }; /* diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/audio/ossaudio.c --- a/tools/ioemu/audio/ossaudio.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/audio/ossaudio.c Thu Sep 27 16:36:23 2007 +0100 @@ -21,10 +21,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include <stdlib.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/ioctl.h> +#if defined(__OpenBSD__) +#include <soundcard.h> +#else #include <sys/soundcard.h> +#endif #include "vl.h" #define AUDIO_CAP "oss" @@ -231,7 +236,7 @@ static int oss_open (int in, struct oss_ goto err; } - if (ioctl (fd, SNDCTL_DSP_NONBLOCK)) { + if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) { oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n"); goto err; } diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/block-raw.c --- a/tools/ioemu/block-raw.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/block-raw.c Thu Sep 27 16:36:23 2007 +0100 @@ -53,8 +53,13 @@ #include <linux/cdrom.h> #include <linux/fd.h> #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) #include <sys/disk.h> +#endif +#if defined(__OpenBSD__) +#include <sys/ioctl.h> +#include <sys/disklabel.h> +#include <sys/dkio.h> #endif //#define DEBUG_FLOPPY @@ -496,6 +501,23 @@ static int raw_truncate(BlockDriverState return 0; } +#ifdef __OpenBSD__ +static int64_t raw_getlength(BlockDriverState *bs) +{ + int fd = ((BDRVRawState*)bs->opaque)->fd; + struct stat st; + if(fstat(fd, &st)) + return -1; + if(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)){ + struct disklabel dl; + if(ioctl(fd, DIOCGDINFO, &dl)) + return -1; + return (uint64_t)dl.d_secsize * + dl.d_partitions[DISKPART(st.st_rdev)].p_size; + }else + return st.st_size; +} +#else /* !__OpenBSD__ */ static int64_t raw_getlength(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; @@ -542,6 +564,7 @@ static int64_t raw_getlength(BlockDrive } return size; } +#endif static int raw_create(const char *filename, int64_t total_size, const char *backing_file, int flags) diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/block-vvfat.c --- a/tools/ioemu/block-vvfat.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/block-vvfat.c Thu Sep 27 16:36:23 2007 +0100 @@ -1017,7 +1017,7 @@ DLOG(if (stderr == NULL) { i = strrchr(dirname, ':') - dirname; assert(i >= 3); - if (dirname[i-2] == ':' && isalpha(dirname[i-1])) + if (dirname[i-2] == ':' && isalpha((uint8_t)dirname[i-1])) /* workaround for DOS drive names */ dirname += i-1; else diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/bswap.h --- a/tools/ioemu/bswap.h Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/bswap.h Thu Sep 27 16:36:23 2007 +0100 @@ -4,6 +4,11 @@ #include "config-host.h" #include <inttypes.h> + +#ifdef _BSD +#include <sys/endian.h> +#include <sys/types.h> +#else #ifdef HAVE_BYTESWAP_H #include <byteswap.h> @@ -73,6 +78,8 @@ static inline void bswap64s(uint64_t *s) *s = bswap64(*s); } +#endif /* _BSD */ + #if defined(WORDS_BIGENDIAN) #define be_bswap(v, size) (v) #define le_bswap(v, size) bswap ## size(v) diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/cutils.c --- a/tools/ioemu/cutils.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/cutils.c Thu Sep 27 16:36:23 2007 +0100 @@ -23,7 +23,7 @@ */ #include "vl.h" -void pstrcpy(char *buf, int buf_size, const char *str) +void pstrcpy(char *buf, size_t buf_size, const char *str) { int c; char *q = buf; @@ -41,7 +41,7 @@ void pstrcpy(char *buf, int buf_size, co } /* strcat and truncate. */ -char *pstrcat(char *buf, int buf_size, const char *s) +char *pstrcat(char *buf, size_t buf_size, const char *s) { int len; len = strlen(buf); @@ -72,7 +72,7 @@ int stristart(const char *str, const cha p = str; q = val; while (*q != '\0') { - if (toupper(*p) != toupper(*q)) + if (toupper((uint8_t)*p) != toupper((uint8_t)*q)) return 0; p++; q++; diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/monitor.c --- a/tools/ioemu/monitor.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/monitor.c Thu Sep 27 16:36:23 2007 +0100 @@ -1698,7 +1698,7 @@ static void next(void) { if (pch != '\0') { pch++; - while (isspace(*pch)) + while (isspace((uint8_t)*pch)) pch++; } } @@ -1756,7 +1756,7 @@ static target_long expr_unary(void) *q++ = *pch; pch++; } - while (isspace(*pch)) + while (isspace((uint8_t)*pch)) pch++; *q = 0; ret = get_monitor_def(&n, buf); @@ -1780,7 +1780,7 @@ static target_long expr_unary(void) expr_error("invalid char in expression"); } pch = p; - while (isspace(*pch)) + while (isspace((uint8_t)*pch)) pch++; break; } @@ -1874,7 +1874,7 @@ static int get_expr(target_long *pval, c *pp = pch; return -1; } - while (isspace(*pch)) + while (isspace((uint8_t)*pch)) pch++; *pval = expr_sum(); *pp = pch; @@ -1890,7 +1890,7 @@ static int get_str(char *buf, int buf_si q = buf; p = *pp; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*p == '\0') { fail: @@ -1935,7 +1935,7 @@ static int get_str(char *buf, int buf_si } p++; } else { - while (*p != '\0' && !isspace(*p)) { + while (*p != '\0' && !isspace((uint8_t)*p)) { if ((q - buf) < buf_size - 1) { *q++ = *p; } @@ -1975,12 +1975,12 @@ static void monitor_handle_command(const /* extract the command name */ p = cmdline; q = cmdname; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*p == '\0') return; pstart = p; - while (*p != '\0' && *p != '/' && !isspace(*p)) + while (*p != '\0' && *p != '/' && !isspace((uint8_t)*p)) p++; len = p - pstart; if (len > sizeof(cmdname) - 1) @@ -2016,7 +2016,7 @@ static void monitor_handle_command(const int ret; char *str; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*typestr == '?') { typestr++; @@ -2058,15 +2058,15 @@ static void monitor_handle_command(const { int count, format, size; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*p == '/') { /* format found */ p++; count = 1; - if (isdigit(*p)) { + if (isdigit((uint8_t)*p)) { count = 0; - while (isdigit(*p)) { + while (isdigit((uint8_t)*p)) { count = count * 10 + (*p - '0'); p++; } @@ -2105,7 +2105,7 @@ static void monitor_handle_command(const } } next: - if (*p != '\0' && !isspace(*p)) { + if (*p != '\0' && !isspace((uint8_t)*p)) { term_printf("invalid char in format: '%c'\n", *p); goto fail; } @@ -2138,7 +2138,7 @@ static void monitor_handle_command(const case 'l': { target_long val; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*typestr == '?' || *typestr == '.') { if (*typestr == '?') { @@ -2149,7 +2149,7 @@ static void monitor_handle_command(const } else { if (*p == '.') { p++; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; has_arg = 1; } else { @@ -2195,7 +2195,7 @@ static void monitor_handle_command(const c = *typestr++; if (c == '\0') goto bad_type; - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; has_option = 0; if (*p == '-') { @@ -2225,7 +2225,7 @@ static void monitor_handle_command(const } } /* check that all arguments were parsed */ - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*p != '\0') { term_printf("%s: extraneous characters at the end of line\n", @@ -2364,7 +2364,7 @@ static void parse_cmdline(const char *cm p = cmdline; nb_args = 0; for(;;) { - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; if (*p == '\0') break; @@ -2398,7 +2398,7 @@ void readline_find_completion(const char /* if the line ends with a space, it means we want to complete the next arg */ len = strlen(cmdline); - if (len > 0 && isspace(cmdline[len - 1])) { + if (len > 0 && isspace((uint8_t)cmdline[len - 1])) { if (nb_args >= MAX_ARGS) return; args[nb_args++] = qemu_strdup(""); diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/osdep.h --- a/tools/ioemu/osdep.h Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/osdep.h Thu Sep 27 16:36:23 2007 +0100 @@ -2,6 +2,10 @@ #define QEMU_OSDEP_H #include <stdarg.h> +#ifdef __OpenBSD__ +#include <sys/types.h> +#include <sys/signal.h> +#endif #define qemu_printf printf diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/target-i386-dm/exec-dm.c --- a/tools/ioemu/target-i386-dm/exec-dm.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/target-i386-dm/exec-dm.c Thu Sep 27 16:36:23 2007 +0100 @@ -168,8 +168,8 @@ void cpu_set_log_filename(const char *fi #else setvbuf(logfile, NULL, _IOLBF, 0); #endif - stdout = logfile; - stderr = logfile; + dup2(fileno(logfile), 1); + dup2(fileno(logfile), 2); } /* mask must never be zero, except for A20 change call */ diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/usb-linux.c --- a/tools/ioemu/usb-linux.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/usb-linux.c Thu Sep 27 16:36:23 2007 +0100 @@ -268,7 +268,7 @@ static int get_tag_value(char *buf, int if (!p) return -1; p += strlen(tag); - while (isspace(*p)) + while (isspace((uint8_t)*p)) p++; q = buf; while (*p != '\0' && !strchr(stopchars, *p)) { diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/vl.c --- a/tools/ioemu/vl.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/vl.c Thu Sep 27 16:36:23 2007 +0100 @@ -24,6 +24,7 @@ #include "vl.h" #include <unistd.h> +#include <stdlib.h> #include <fcntl.h> #include <signal.h> #include <time.h> @@ -38,22 +39,29 @@ #include <sys/poll.h> #include <sys/mman.h> #include <sys/ioctl.h> +#include <sys/resource.h> #include <sys/socket.h> #include <netinet/in.h> +#include <net/if.h> +#if defined(__NetBSD__) +#include <net/if_tap.h> +#endif +#if defined(__linux__) || defined(__Linux__) +#include <linux/if_tun.h> +#endif #include <arpa/inet.h> #include <dirent.h> #include <netdb.h> #ifdef _BSD #include <sys/stat.h> -#ifndef __APPLE__ +#ifndef _BSD #include <libutil.h> +#else +#include <util.h> #endif #else #ifndef __sun__ -#include <linux/if.h> -#include <linux/if_tun.h> #include <pty.h> -#include <malloc.h> #include <linux/rtc.h> #include <linux/ppdev.h> #endif @@ -65,7 +73,6 @@ #endif #ifdef _WIN32 -#include <malloc.h> #include <sys/timeb.h> #include <windows.h> #define getopt_long_only getopt_long @@ -91,7 +98,11 @@ #include <xen/hvm/params.h> #define DEFAULT_NETWORK_SCRIPT "/etc/xen/qemu-ifup" +#ifdef _BSD +#define DEFAULT_BRIDGE "bridge0" +#else #define DEFAULT_BRIDGE "xenbr0" +#endif #ifdef __sun__ #define SMBD_COMMAND "/usr/sfw/sbin/smbd" #else @@ -1794,7 +1805,7 @@ static int store_dev_info(char *devName, return 0; } -#if defined(__linux__) +#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) static CharDriverState *qemu_chr_open_pty(void) { struct termios tty; @@ -1949,6 +1960,7 @@ static CharDriverState *qemu_chr_open_tt return chr; } +#if defined(__linux__) static int pp_ioctl(CharDriverState *chr, int cmd, void *arg) { int fd = (int)chr->opaque; @@ -2013,13 +2025,14 @@ static CharDriverState *qemu_chr_open_pp return chr; } +#endif /* __linux__ */ #else static CharDriverState *qemu_chr_open_pty(void) { return NULL; } -#endif +#endif /* __linux__ || __NetBSD__ || __OpenBSD__ */ #endif /* !defined(_WIN32) */ @@ -2958,7 +2971,7 @@ static int parse_macaddr(uint8_t *macadd return 0; } -static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) +static int get_str_sep(char *buf, size_t buf_size, const char **pp, int sep) { const char *p, *p1; int len; @@ -3031,7 +3044,7 @@ int parse_host_port(struct sockaddr_in * if (buf[0] == '\0') { saddr->sin_addr.s_addr = 0; } else { - if (isdigit(buf[0])) { + if (isdigit((uint8_t)buf[0])) { if (!inet_aton(buf, &saddr->sin_addr)) return -1; } else { @@ -3373,18 +3386,30 @@ static int tap_open(char *ifname, int if static int tap_open(char *ifname, int ifname_size) { int fd; +#ifndef TAPGIFNAME char *dev; struct stat s; +#endif + struct ifreq ifr; fd = open("/dev/tap", O_RDWR); if (fd < 0) { - fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n"); + fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation %s\n", strerror(errno)); return -1; } +#ifdef TAPGIFNAME + if (ioctl (fd, TAPGIFNAME, (void*)&ifr) < 0) { + fprintf(stderr, "warning: could not open get tap name: %s\n", + strerror(errno)); + return -1; + } + pstrcpy(ifname, ifname_size, ifr.ifr_name); +#else fstat(fd, &s); dev = devname(s.st_rdev, S_IFCHR); pstrcpy(ifname, ifname_size, dev); +#endif fcntl(fd, F_SETFL, O_NONBLOCK); return fd; @@ -3434,6 +3459,8 @@ static int net_tap_init(VLANState *vlan, char *args[4]; char **parg; char ifname[128]; + + memset(ifname, 0, sizeof(ifname)); if (ifname1 != NULL) pstrcpy(ifname, sizeof(ifname), ifname1); @@ -3611,7 +3638,7 @@ static int net_socket_mcast_create(struc val = 1; ret=setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, - (const char *)&val, sizeof(val)); + (const char *)&val, sizeof(char)); if (ret < 0) { perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)"); goto fail; @@ -3893,7 +3920,7 @@ static int net_socket_mcast_init(VLANSta } -static int get_param_value(char *buf, int buf_size, +static int get_param_value(char *buf, size_t buf_size, const char *tag, const char *str) { const char *p; @@ -4019,6 +4046,10 @@ static int net_client_init(const char *s char setup_script[1024]; char bridge[16]; int fd; + + memset(ifname, 0, sizeof(ifname)); + memset(setup_script, 0, sizeof(setup_script)); + if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { fd = strtol(buf, NULL, 0); ret = -1; @@ -6914,7 +6945,6 @@ static int qemu_map_cache_init(void) nr_buckets = (((MAX_MCACHE_SIZE >> PAGE_SHIFT) + (1UL << (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)) - 1) >> (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)); - fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx\n", nr_buckets); /* * Use mmap() directly: lets us allocate a big hash table with no up-front @@ -6923,8 +6953,9 @@ static int qemu_map_cache_init(void) */ size = nr_buckets * sizeof(struct map_cache); size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); + fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx size %lu\n", nr_buckets, size); mapcache_entry = mmap(NULL, size, PROT_READ|PROT_WRITE, - MAP_SHARED|MAP_ANONYMOUS, 0, 0); + MAP_SHARED|MAP_ANON, -1, 0); if (mapcache_entry == MAP_FAILED) { errno = ENOMEM; return -1; @@ -7061,6 +7092,7 @@ int main(int argc, char **argv) unsigned long ioreq_pfn; extern void *shared_page; extern void *buffered_io_page; + struct rlimit rl; #ifdef __ia64__ unsigned long nr_pages; xen_pfn_t *page_array; @@ -7069,6 +7101,30 @@ int main(int argc, char **argv) sigset_t set; char qemu_dm_logfilename[128]; const char *direct_pci = NULL; + + /* Maximise rlimits. Needed where default constraints are tight (*BSD). */ + if (getrlimit(RLIMIT_STACK, &rl) != 0) { + perror("getrlimit(RLIMIT_STACK)"); + exit(1); + } + rl.rlim_cur = rl.rlim_max; + if (setrlimit(RLIMIT_STACK, &rl) != 0) + perror("setrlimit(RLIMIT_STACK)"); + if (getrlimit(RLIMIT_DATA, &rl) != 0) { + perror("getrlimit(RLIMIT_DATA)"); + exit(1); + } + rl.rlim_cur = rl.rlim_max; + if (setrlimit(RLIMIT_DATA, &rl) != 0) + perror("setrlimit(RLIMIT_DATA)"); + rl.rlim_cur = RLIM_INFINITY; + rl.rlim_max = RLIM_INFINITY; + if (setrlimit(RLIMIT_RSS, &rl) != 0) + perror("setrlimit(RLIMIT_RSS)"); + rl.rlim_cur = RLIM_INFINITY; + rl.rlim_max = RLIM_INFINITY; + if (setrlimit(RLIMIT_MEMLOCK, &rl) != 0) + perror("setrlimit(RLIMIT_MEMLOCK)"); /* Ensure that SIGUSR2 is blocked by default when a new thread is created, then only the threads that use the signal unblock it -- this fixes a diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/vl.h --- a/tools/ioemu/vl.h Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/vl.h Thu Sep 27 16:36:23 2007 +0100 @@ -103,8 +103,8 @@ static inline char *realpath(const char #endif /* cutils.c */ -void pstrcpy(char *buf, int buf_size, const char *str); -char *pstrcat(char *buf, int buf_size, const char *s); +void pstrcpy(char *buf, size_t buf_size, const char *str); +char *pstrcat(char *buf, size_t buf_size, const char *s); int strstart(const char *str, const char *val, const char **ptr); int stristart(const char *str, const char *val, const char **ptr); diff -r 98d97e3ad29a -r 04cc0e22a20a tools/ioemu/vnc.c --- a/tools/ioemu/vnc.c Thu Sep 27 15:22:29 2007 +0100 +++ b/tools/ioemu/vnc.c Thu Sep 27 16:36:23 2007 +0100 @@ -24,6 +24,9 @@ * THE SOFTWARE. */ +#include <sys/stat.h> +#include <sys/socket.h> +#include <netinet/in.h> #include "vl.h" #include "qemu_socket.h" #include <assert.h> _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |