X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Fiface-socket.c;h=7f0328c0fd53aac3deb6b9ba6aa6505a309ed914;hb=31281ec866f7244baf965402aebc8e26046b43e0;hp=7407f5fa9168474b2ec69422fdc2a09243e13be8;hpb=cd265a5242baa89c2149b5c5cbf0ed00cfa83892;p=palacios.git diff --git a/linux_module/iface-socket.c b/linux_module/iface-socket.c index 7407f5f..7f0328c 100644 --- a/linux_module/iface-socket.c +++ b/linux_module/iface-socket.c @@ -1,24 +1,8 @@ -/* - * This file is part of the Palacios Virtual Machine Monitor developed - * by the V3VEE Project with funding from the United States National - * Science Foundation and the Department of Energy. - * - * The V3VEE Project is a joint project between Northwestern University - * and the University of New Mexico. You can find out more at - * http://www.v3vee.org - * - * Copyright (c) 2010, Lei Xia - * Copyright (c) 2010, The V3VEE Project - * All rights reserved. - * - * This is free software. You are permitted to use, redistribute, - * and modify it under the terms of the GNU General Public License - * Version 2 (GPLv2). The accompanying COPYING file contains the - * full text of the license. - */ - /* +/* * Palacios Socket Interface Implementation + * (c) Lei Xia 2010 */ + #include @@ -67,19 +51,26 @@ palacios_tcp_socket(const int bufsize, const int nodelay, vm_state = get_vm_ext_data(guest, "SOCKET_INTERFACE"); if (vm_state == NULL) { - printk("ERROR: Could not locate vm socket state for extension SOCKET_INTERFACE\n"); + ERROR("ERROR: Could not locate vm socket state for extension SOCKET_INTERFACE\n"); return NULL; } } - sock = kmalloc(sizeof(struct palacios_socket), GFP_KERNEL); + sock = palacios_alloc(sizeof(struct palacios_socket)); + + if (!sock) { + ERROR("Cannot allocate TCP socket\n"); + return NULL; + } + memset(sock, 0, sizeof(struct palacios_socket)); err = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &(sock->sock)); if (err < 0) { - kfree(sock); + ERROR("Cannot create TCP socket\n"); + palacios_free(sock); return NULL; } @@ -111,19 +102,25 @@ palacios_udp_socket( vm_state = get_vm_ext_data(guest, "SOCKET_INTERFACE"); if (vm_state == NULL) { - printk("ERROR: Could not locate vm socket state for extension SOCKET_INTERFACE\n"); + ERROR("ERROR: Could not locate vm socket state for extension SOCKET_INTERFACE\n"); return NULL; } } - sock = kmalloc(sizeof(struct palacios_socket), GFP_KERNEL); + sock = palacios_alloc(sizeof(struct palacios_socket)); + if (!sock) { + ERROR("Cannot allocate UDP socket\n"); + return NULL; + } + memset(sock, 0, sizeof(struct palacios_socket)); err = sock_create(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &(sock->sock)) ; if (err < 0){ - kfree(sock); + ERROR("Cannot create UDP socket\n"); + palacios_free(sock); return NULL; } @@ -149,7 +146,7 @@ palacios_close(void * sock_ptr) sock->sock->ops->release(sock->sock); list_del(&(sock->sock_node)); - kfree(sock); + palacios_free(sock); } } @@ -203,18 +200,24 @@ static void * palacios_accept(const void * sock_ptr, unsigned int * remote_ip, u vm_state = get_vm_ext_data(sock->guest, "SOCKET_INTERFACE"); if (vm_state == NULL) { - printk("ERROR: Could not locate vm socket state for extension SOCKET_INTERFACE\n"); + ERROR("Could not locate vm socket state for extension SOCKET_INTERFACE\n"); return NULL; } } - newsock = kmalloc(sizeof(struct palacios_socket), GFP_KERNEL); + newsock = palacios_alloc(sizeof(struct palacios_socket)); + + if (!newsock) { + ERROR("Cannot allocate new socket on accept\n"); + return NULL; + } err = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &(newsock->sock)); if (err < 0) { - kfree(newsock); + ERROR("Cannot create new socket on accept\n"); + palacios_free(newsock); return NULL; } @@ -224,7 +227,8 @@ static void * palacios_accept(const void * sock_ptr, unsigned int * remote_ip, u err = newsock->sock->ops->accept(sock->sock, newsock->sock, 0); if (err < 0){ - kfree(newsock); + ERROR("Cannot accept\n"); + palacios_free(newsock); return NULL; } @@ -410,7 +414,6 @@ palacios_recvfrom_ip( { struct palacios_socket * sock = (struct palacios_socket *)sock_ptr; struct sockaddr_in src; - int alen; struct msghdr msg; mm_segment_t oldfs; struct iovec iov; @@ -423,7 +426,6 @@ palacios_recvfrom_ip( src.sin_family = AF_INET; src.sin_port = htons(port); src.sin_addr.s_addr = htonl(ip_addr); - alen = sizeof(src); msg.msg_flags = 0; @@ -473,7 +475,7 @@ static int socket_init( void ) { static int socket_deinit( void ) { if (!list_empty(&(global_sockets))) { - printk("Error removing module with open sockets\n"); + ERROR("Error removing module with open sockets\n"); } return 0;