debuggers.hg

changeset 20828:5b45d08b7abf

blktap: make memshr optional

Attached patch makes memshr optional for blktap/blktap2.
This fixes build for platforms where memshr isn't build on.
While there, make indentation consistent.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jan 12 07:01:21 2010 +0000 (2010-01-12)
parents 5e1971bec881
children 3edbffaab206
files tools/blktap/drivers/Makefile tools/blktap/drivers/blktapctrl.c tools/blktap2/drivers/Makefile tools/blktap2/drivers/tapdisk-image.c tools/blktap2/drivers/tapdisk-vbd.c tools/blktap2/drivers/tapdisk.h tools/blktap2/drivers/tapdisk2.c
line diff
     1.1 --- a/tools/blktap/drivers/Makefile	Tue Jan 12 06:56:56 2010 +0000
     1.2 +++ b/tools/blktap/drivers/Makefile	Tue Jan 12 07:01:21 2010 +0000
     1.3 @@ -23,7 +23,13 @@ CRYPT_LIB := -lcrypto
     1.4  $(warning === libgcrypt not installed: falling back to libcrypto ===)
     1.5  endif
     1.6  
     1.7 -LDFLAGS_blktapctrl := $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenstore) $(MEMSHR_DIR)/libmemshr.a -L../lib -lblktap -lrt -lm
     1.8 +MEMSHRLIBS :=
     1.9 +ifeq ($(CONFIG_Linux), y)
    1.10 +CFLAGS += -DMEMSHR
    1.11 +MEMSHRLIBS += $(MEMSHR_DIR)/libmemshr.a
    1.12 +endif
    1.13 +
    1.14 +LDFLAGS_blktapctrl := $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenstore) $(MEMSHRLIBS) -L../lib -lblktap -lrt -lm
    1.15  LDFLAGS_img := $(LIBAIO_DIR)/libaio.a $(CRYPT_LIB) -lpthread -lz
    1.16  
    1.17  BLK-OBJS-y  := block-aio.o
     2.1 --- a/tools/blktap/drivers/blktapctrl.c	Tue Jan 12 06:56:56 2010 +0000
     2.2 +++ b/tools/blktap/drivers/blktapctrl.c	Tue Jan 12 07:01:21 2010 +0000
     2.3 @@ -859,7 +859,9 @@ int main(int argc, char *argv[])
     2.4  		goto open_failed;
     2.5  	}
     2.6  
     2.7 -    memshr_daemon_initialize();
     2.8 +#ifdef MEMSHR
     2.9 +	memshr_daemon_initialize();
    2.10 +#endif
    2.11  
    2.12   retry:
    2.13  	/* Set up store connection and watch. */
     3.1 --- a/tools/blktap2/drivers/Makefile	Tue Jan 12 06:56:56 2010 +0000
     3.2 +++ b/tools/blktap2/drivers/Makefile	Tue Jan 12 07:01:21 2010 +0000
     3.3 @@ -55,7 +55,13 @@ REMUS-OBJS  += hashtable_utility.o
     3.4  
     3.5  LIBAIO_DIR = $(XEN_ROOT)/tools/libaio/src
     3.6  MEMSHR_DIR = $(XEN_ROOT)/tools/memshr
     3.7 -MEMSHRLIBS := $(MEMSHR_DIR)/libmemshr.a
     3.8 +
     3.9 +MEMSHRLIBS :=
    3.10 +ifeq ($(CONFIG_Linux), y)
    3.11 +CFLAGS += -DMEMSHR
    3.12 +MEMSHRLIBS += $(MEMSHR_DIR)/libmemshr.a
    3.13 +endif
    3.14 +
    3.15  tapdisk2 tapdisk-stream tapdisk-diff $(QCOW_UTIL): AIOLIBS := $(LIBAIO_DIR)/libaio.a 
    3.16  tapdisk-client tapdisk-stream tapdisk-diff $(QCOW_UTIL): CFLAGS  += -I$(LIBAIO_DIR) -I$(XEN_LIBXC)
    3.17  
     4.1 --- a/tools/blktap2/drivers/tapdisk-image.c	Tue Jan 12 06:56:56 2010 +0000
     4.2 +++ b/tools/blktap2/drivers/tapdisk-image.c	Tue Jan 12 07:01:21 2010 +0000
     4.3 @@ -28,7 +28,9 @@
     4.4  #include <errno.h>
     4.5  #include <unistd.h>
     4.6  #include <stdlib.h>
     4.7 +#ifdef MEMSHR
     4.8  #include <memshr.h>
     4.9 +#endif
    4.10  
    4.11  #include "tapdisk-image.h"
    4.12  #include "tapdisk-driver.h"
    4.13 @@ -57,7 +59,9 @@ tapdisk_image_allocate(char *file, int t
    4.14  	image->flags     = flags;
    4.15  	image->storage   = storage;
    4.16  	image->private   = private;
    4.17 -    image->memshr_id = memshr_vbd_image_get(file);
    4.18 +#ifdef MEMSHR
    4.19 +	image->memshr_id = memshr_vbd_image_get(file);
    4.20 +#endif
    4.21  	INIT_LIST_HEAD(&image->next);
    4.22  
    4.23  	return image;
    4.24 @@ -71,7 +75,9 @@ tapdisk_image_free(td_image_t *image)
    4.25  
    4.26  	list_del(&image->next);
    4.27  
    4.28 -    memshr_vbd_image_put(image->memshr_id);
    4.29 +#ifdef MEMSHR
    4.30 +	memshr_vbd_image_put(image->memshr_id);
    4.31 +#endif
    4.32  	free(image->name);
    4.33  	tapdisk_driver_free(image->driver);
    4.34  	free(image);
     5.1 --- a/tools/blktap2/drivers/tapdisk-vbd.c	Tue Jan 12 06:56:56 2010 +0000
     5.2 +++ b/tools/blktap2/drivers/tapdisk-vbd.c	Tue Jan 12 07:01:21 2010 +0000
     5.3 @@ -34,7 +34,9 @@
     5.4  #include <libgen.h>
     5.5  #include <sys/mman.h>
     5.6  #include <sys/ioctl.h>
     5.7 +#ifdef MEMSHR
     5.8  #include <memshr.h>
     5.9 +#endif
    5.10  
    5.11  #include "libvhd.h"
    5.12  #include "tapdisk-image.h"
    5.13 @@ -107,7 +109,9 @@ tapdisk_vbd_initialize(int rfd, int wfd,
    5.14  	vbd->callback = tapdisk_vbd_callback;
    5.15  	vbd->argument = vbd;
    5.16      
    5.17 -    memshr_vbd_initialize();
    5.18 +#ifdef MEMSHR
    5.19 +	memshr_vbd_initialize();
    5.20 +#endif
    5.21  
    5.22  	INIT_LIST_HEAD(&vbd->driver_stack);
    5.23  	INIT_LIST_HEAD(&vbd->images);
    5.24 @@ -1455,18 +1459,23 @@ static void
    5.25  			    (treq.op == TD_OP_WRITE ? "write" : "read"),
    5.26  			    treq.secs, treq.sec);
    5.27  		}
    5.28 -	} else 
    5.29 -    if(treq.op == TD_OP_READ && td_flag_test(image->flags, TD_OPEN_RDONLY)) {
    5.30 -        uint64_t         hnd  = treq.memshr_hnd;
    5.31 -        uint16_t         uid  = image->memshr_id;
    5.32 -        blkif_request_t *breq = &vreq->req;
    5.33 -        uint64_t         sec  = tapdisk_vbd_breq_get_sector(breq, treq);
    5.34 -        int              secs = breq->seg[treq.sidx].last_sect -
    5.35 -                                breq->seg[treq.sidx].first_sect + 1;
    5.36 +	} else {
    5.37 +#ifdef MEMSHR
    5.38 +		if (treq.op == TD_OP_READ
    5.39 +		   && td_flag_test(image->flags, TD_OPEN_RDONLY)) {
    5.40 +			uint64_t hnd  = treq.memshr_hnd;
    5.41 +			uint16_t uid  = image->memshr_id;
    5.42 +			blkif_request_t *breq = &vreq->req;
    5.43 +			uint64_t sec  = tapdisk_vbd_breq_get_sector(breq, treq);
    5.44 +			int secs = breq->seg[treq.sidx].last_sect -
    5.45 +			    breq->seg[treq.sidx].first_sect + 1;
    5.46  
    5.47 -        if(hnd != 0)
    5.48 -            memshr_vbd_complete_ro_request(hnd, uid, sec, secs);
    5.49 -    }
    5.50 +			if (hnd != 0)
    5.51 +				memshr_vbd_complete_ro_request(hnd, uid,
    5.52 +								sec, secs);
    5.53 +		}
    5.54 +#endif
    5.55 +	}
    5.56  
    5.57  	tapdisk_vbd_complete_vbd_request(vbd, vreq);
    5.58  }
    5.59 @@ -1518,29 +1527,28 @@ static void
    5.60  		break;
    5.61  
    5.62  	case TD_OP_READ:
    5.63 -        if(td_flag_test(parent->flags, TD_OPEN_RDONLY))
    5.64 -        {
    5.65 -            int ret, seg = treq.sidx;
    5.66 -            blkif_request_t *breq = &vreq->req;
    5.67 +#ifdef MEMSHR
    5.68 +		if(td_flag_test(parent->flags, TD_OPEN_RDONLY)) {
    5.69 +			int ret, seg = treq.sidx;
    5.70 +			blkif_request_t *breq = &vreq->req;
    5.71          
    5.72 -            ret = memshr_vbd_issue_ro_request(treq.buf,
    5.73 -                                              breq->seg[seg].gref,
    5.74 -                                              parent->memshr_id,
    5.75 -                                              treq.sec,
    5.76 -                                              treq.secs,
    5.77 -                                              &treq.memshr_hnd);
    5.78 -            if(ret == 0)
    5.79 -            {
    5.80 -                /* Reset memshr handle. This'll prevent
    5.81 -                 * memshr_vbd_complete_ro_request being called */
    5.82 -                treq.memshr_hnd = 0;
    5.83 -                td_complete_request(treq, 0);
    5.84 -            }
    5.85 -            else
    5.86 -		        td_queue_read(parent, treq);
    5.87 -        }
    5.88 -        else
    5.89 -		    td_queue_read(parent, treq);
    5.90 +			ret = memshr_vbd_issue_ro_request(treq.buf,
    5.91 +			      breq->seg[seg].gref,
    5.92 +			      parent->memshr_id,
    5.93 +			      treq.sec,
    5.94 +			      treq.secs,
    5.95 +			      &treq.memshr_hnd);
    5.96 +			if(ret == 0) {
    5.97 +				/* Reset memshr handle. This'll prevent
    5.98 +				 * memshr_vbd_complete_ro_request being called
    5.99 +				 */
   5.100 +				treq.memshr_hnd = 0;
   5.101 +				td_complete_request(treq, 0);
   5.102 +			} else
   5.103 +				td_queue_read(parent, treq);
   5.104 +		} else
   5.105 +#endif
   5.106 +			td_queue_read(parent, treq);
   5.107  		break;
   5.108  	}
   5.109  
     6.1 --- a/tools/blktap2/drivers/tapdisk.h	Tue Jan 12 06:56:56 2010 +0000
     6.2 +++ b/tools/blktap2/drivers/tapdisk.h	Tue Jan 12 07:01:21 2010 +0000
     6.3 @@ -132,7 +132,9 @@ struct td_request {
     6.4  	int                          sidx;
     6.5  	void                        *private;
     6.6      
     6.7 -    uint64_t                     memshr_hnd;
     6.8 +#ifdef MEMSHR
     6.9 +	uint64_t                     memshr_hnd;
    6.10 +#endif
    6.11  };
    6.12  
    6.13  /* 
     7.1 --- a/tools/blktap2/drivers/tapdisk2.c	Tue Jan 12 06:56:56 2010 +0000
     7.2 +++ b/tools/blktap2/drivers/tapdisk2.c	Tue Jan 12 07:01:21 2010 +0000
     7.3 @@ -34,7 +34,9 @@
     7.4  #include <sys/stat.h>
     7.5  #include <sys/types.h>
     7.6  #include <sys/ioctl.h>
     7.7 +#ifdef MEMSHR
     7.8  #include <memshr.h>
     7.9 +#endif
    7.10  
    7.11  #include "tapdisk.h"
    7.12  #include "blktap2.h"
    7.13 @@ -419,10 +421,15 @@ main(int argc, char *argv[])
    7.14  			break;
    7.15  		case 'h':
    7.16  			usage(argv[0], 0);
    7.17 -            break;
    7.18 -        case 's':
    7.19 -            memshr_set_domid(atoi(optarg));
    7.20 -            break;
    7.21 +			break;
    7.22 +		case 's':
    7.23 +#ifdef MEMSHR
    7.24 +			memshr_set_domid(atoi(optarg));
    7.25 +#else
    7.26 +			fprintf(stderr, "MEMSHR support not compiled in.\n");
    7.27 +			exit(EXIT_FAILURE);
    7.28 +#endif
    7.29 +			break;
    7.30  		default:
    7.31  			usage(argv[0], EINVAL);
    7.32  		}