direct-io.hg

changeset 12269:862aca401601

[BLKTAP] Various cleanups necessary for ia64 support.
- remove magic number 8 and 64.
page size / sector size is 8 on x86, however on ia64 page size is
16kb.
blkring size is 64 on x86. however it's 128 on ia64.
- replace 0xFFFF with INVALID_GRANT_HANDLE
- don't map io ring into user space with uncachable.
kernel access the page with cacable and tapdisk uses memory barrier
so that it isn't necessary.
- remove printk warning and inserted new line.
- remove unused variable, page.
- add one BUG()

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author kfraser@localhost.localdomain
date Tue Nov 07 11:01:35 2006 +0000 (2006-11-07)
parents 6f3c40ee2488
children 3cc7e419b949
files linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c tools/blktap/drivers/blktapctrl.c tools/blktap/drivers/tapdisk.c tools/blktap/drivers/tapdisk.h tools/blktap/lib/blktaplib.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Tue Nov 07 10:48:48 2006 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Tue Nov 07 11:01:35 2006 +0000
     1.3 @@ -93,8 +93,9 @@ int setup_xen_class(void)
     1.4   * mmap_alloc is initialised to 2 and should be adjustable on the fly via
     1.5   * sysfs.
     1.6   */
     1.7 -#define MAX_DYNAMIC_MEM 64
     1.8 -#define MAX_PENDING_REQS 64   
     1.9 +#define BLK_RING_SIZE		__RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
    1.10 +#define MAX_DYNAMIC_MEM		BLK_RING_SIZE
    1.11 +#define MAX_PENDING_REQS	BLK_RING_SIZE
    1.12  #define MMAP_PAGES (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
    1.13  #define MMAP_VADDR(_start, _req,_seg)                                   \
    1.14          (_start +                                                       \
    1.15 @@ -215,6 +216,7 @@ struct grant_handle_pair
    1.16          grant_handle_t kernel;
    1.17          grant_handle_t user;
    1.18  };
    1.19 +#define INVALID_GRANT_HANDLE	0xFFFF
    1.20  
    1.21  static struct grant_handle_pair 
    1.22      pending_grant_handles[MAX_DYNAMIC_MEM][MMAP_PAGES];
    1.23 @@ -293,10 +295,11 @@ static inline int GET_NEXT_REQ(unsigned 
    1.24  
    1.25  
    1.26  #define BLKTAP_INVALID_HANDLE(_g) \
    1.27 -    (((_g->kernel) == 0xFFFF) && ((_g->user) == 0xFFFF))
    1.28 +    (((_g->kernel) == INVALID_GRANT_HANDLE) &&  \
    1.29 +     ((_g->user) == INVALID_GRANT_HANDLE))
    1.30  
    1.31  #define BLKTAP_INVALIDATE_HANDLE(_g) do {       \
    1.32 -    (_g)->kernel = 0xFFFF; (_g)->user = 0xFFFF; \
    1.33 +    (_g)->kernel = INVALID_GRANT_HANDLE; (_g)->user = INVALID_GRANT_HANDLE; \
    1.34      } while(0)
    1.35  
    1.36  
    1.37 @@ -588,8 +591,6 @@ static int blktap_mmap(struct file *filp
    1.38  	info->user_vstart  = info->rings_vstart + (RING_PAGES << PAGE_SHIFT);
    1.39      
    1.40  	/* Map the ring pages to the start of the region and reserve it. */
    1.41 -	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
    1.42 -
    1.43  	if (remap_pfn_range(vma, vma->vm_start, 
    1.44  			    __pa(info->ufe_ring.sring) >> PAGE_SHIFT, 
    1.45  			    PAGE_SIZE, vma->vm_page_prot)) {
    1.46 @@ -892,14 +893,14 @@ static void fast_flush_area(pending_req_
    1.47  
    1.48  		khandle = &pending_handle(mmap_idx, k_idx, i);
    1.49  
    1.50 -		if (khandle->kernel != 0xFFFF) {
    1.51 +		if (khandle->kernel != INVALID_GRANT_HANDLE) {
    1.52  			gnttab_set_unmap_op(&unmap[invcount],
    1.53  					    idx_to_kaddr(mmap_idx, k_idx, i),
    1.54  					    GNTMAP_host_map, khandle->kernel);
    1.55  			invcount++;
    1.56  		}
    1.57  
    1.58 -		if (khandle->user != 0xFFFF) {
    1.59 +		if (khandle->user != INVALID_GRANT_HANDLE) {
    1.60  			if (create_lookup_pte_addr(
    1.61  				info->vma->vm_mm,
    1.62  				MMAP_VADDR(info->user_vstart, u_idx, i),
    1.63 @@ -1186,8 +1187,10 @@ static void dispatch_rw_block_io(blkif_t
    1.64  
    1.65  	/* Check we have space on user ring - should never fail. */
    1.66  	usr_idx = GET_NEXT_REQ(info->idx_map);
    1.67 -	if (usr_idx == INVALID_REQ)
    1.68 +	if (usr_idx == INVALID_REQ) {
    1.69 +		BUG();
    1.70  		goto fail_response;
    1.71 +	}
    1.72  
    1.73  	/* Check that number of segments is sane. */
    1.74  	nseg = req->nr_segments;
    1.75 @@ -1221,14 +1224,12 @@ static void dispatch_rw_block_io(blkif_t
    1.76  		unsigned long uvaddr;
    1.77  		unsigned long kvaddr;
    1.78  		uint64_t ptep;
    1.79 -		struct page *page;
    1.80  		uint32_t flags;
    1.81  
    1.82  		uvaddr = MMAP_VADDR(info->user_vstart, usr_idx, i);
    1.83  		kvaddr = idx_to_kaddr(mmap_idx, pending_idx, i);
    1.84 -		page = virt_to_page(kvaddr);
    1.85  
    1.86 -		sector = req->sector_number + (8*i);
    1.87 +		sector = req->sector_number + ((PAGE_SIZE / 512) * i);
    1.88  		if( (blkif->sectors > 0) && (sector >= blkif->sectors) ) {
    1.89  			WPRINTK("BLKTAP: Sector request greater" 
    1.90  			       "than size\n");
    1.91 @@ -1238,7 +1239,7 @@ static void dispatch_rw_block_io(blkif_t
    1.92  				BLKIF_OP_WRITE ? "WRITE" : "READ"),
    1.93  				(long long unsigned) sector,
    1.94  				(long long unsigned) sector>>9,
    1.95 -				blkif->sectors);
    1.96 +				(long long unsigned) blkif->sectors);
    1.97  		}
    1.98  
    1.99  		flags = GNTMAP_host_map;
   1.100 @@ -1281,14 +1282,14 @@ static void dispatch_rw_block_io(blkif_t
   1.101  			WPRINTK("invalid kernel buffer -- "
   1.102  				"could not remap it\n");
   1.103  			ret |= 1;
   1.104 -			map[i].handle = 0xFFFF;
   1.105 +			map[i].handle = INVALID_GRANT_HANDLE;
   1.106  		}
   1.107  
   1.108  		if (unlikely(map[i+1].status != 0)) {
   1.109  			WPRINTK("invalid user buffer -- "
   1.110  				"could not remap it\n");
   1.111  			ret |= 1;
   1.112 -			map[i+1].handle = 0xFFFF;
   1.113 +			map[i+1].handle = INVALID_GRANT_HANDLE;
   1.114  		}
   1.115  
   1.116  		pending_handle(mmap_idx, pending_idx, i/2).kernel 
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Tue Nov 07 10:48:48 2006 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Tue Nov 07 11:01:35 2006 +0000
     2.3 @@ -189,7 +189,7 @@ static int blktap_probe(struct xenbus_de
     2.4  	return 0;
     2.5  
     2.6  fail:
     2.7 -	DPRINTK("blktap probe failed");
     2.8 +	DPRINTK("blktap probe failed\n");
     2.9  	blktap_remove(dev);
    2.10  	return err;
    2.11  }
    2.12 @@ -243,7 +243,7 @@ static void tap_frontend_changed(struct 
    2.13  	struct backend_info *be = dev->dev.driver_data;
    2.14  	int err;
    2.15  
    2.16 -	DPRINTK("");
    2.17 +	DPRINTK("\n");
    2.18  
    2.19  	switch (frontend_state) {
    2.20  	case XenbusStateInitialising:
    2.21 @@ -318,7 +318,7 @@ static int connect_ring(struct backend_i
    2.22  	unsigned int evtchn;
    2.23  	int err;
    2.24  
    2.25 -	DPRINTK("%s", dev->otherend);
    2.26 +	DPRINTK("%s\n", dev->otherend);
    2.27  
    2.28  	err = xenbus_gather(XBT_NIL, dev->otherend, "ring-ref", "%lu", 
    2.29  			    &ring_ref, "event-channel", "%u", &evtchn, NULL);
     3.1 --- a/tools/blktap/drivers/blktapctrl.c	Tue Nov 07 10:48:48 2006 +0000
     3.2 +++ b/tools/blktap/drivers/blktapctrl.c	Tue Nov 07 11:01:35 2006 +0000
     3.3 @@ -607,9 +607,11 @@ int main(int argc, char *argv[])
     3.4  	struct xs_handle *h;
     3.5  	struct pollfd  pfd[NUM_POLL_FDS];
     3.6  	pid_t process;
     3.7 +	char buf[128];
     3.8  
     3.9  	__init_blkif();
    3.10 -	openlog("BLKTAPCTRL", LOG_CONS|LOG_ODELAY, LOG_DAEMON);
    3.11 +	snprintf(buf, sizeof(buf), "BLKTAPCTRL[%d]", getpid());
    3.12 +	openlog(buf, LOG_CONS|LOG_ODELAY, LOG_DAEMON);
    3.13  	daemon(0,0);
    3.14  
    3.15  	print_drivers();
     4.1 --- a/tools/blktap/drivers/tapdisk.c	Tue Nov 07 10:48:48 2006 +0000
     4.2 +++ b/tools/blktap/drivers/tapdisk.c	Tue Nov 07 11:01:35 2006 +0000
     4.3 @@ -562,12 +562,14 @@ int main(int argc, char *argv[])
     4.4  	fd_list_entry_t *ptr;
     4.5  	struct tap_disk *drv;
     4.6  	struct td_state *s;
     4.7 +	char openlogbuf[128];
     4.8  	
     4.9  	if (argc != 3) usage();
    4.10  
    4.11  	daemonize();
    4.12  
    4.13 -	openlog("TAPDISK", LOG_CONS|LOG_ODELAY, LOG_DAEMON);
    4.14 +	snprintf(openlogbuf, sizeof(openlogbuf), "TAPDISK[%d]", getpid());
    4.15 +	openlog(openlogbuf, LOG_CONS|LOG_ODELAY, LOG_DAEMON);
    4.16  	/*Setup signal handlers*/
    4.17  	signal (SIGBUS, sig_handler);
    4.18  	signal (SIGINT, sig_handler);
     5.1 --- a/tools/blktap/drivers/tapdisk.h	Tue Nov 07 10:48:48 2006 +0000
     5.2 +++ b/tools/blktap/drivers/tapdisk.h	Tue Nov 07 11:01:35 2006 +0000
     5.3 @@ -61,7 +61,6 @@
     5.4  
     5.5  /* Things disks need to know about, these should probably be in a higher-level
     5.6   * header. */
     5.7 -#define MAX_REQUESTS            64
     5.8  #define MAX_SEGMENTS_PER_REQ    11
     5.9  #define SECTOR_SHIFT             9
    5.10  #define DEFAULT_SECTOR_SIZE    512
     6.1 --- a/tools/blktap/lib/blktaplib.h	Tue Nov 07 10:48:48 2006 +0000
     6.2 +++ b/tools/blktap/lib/blktaplib.h	Tue Nov 07 11:01:35 2006 +0000
     6.3 @@ -41,7 +41,7 @@
     6.4  #include <sys/types.h>
     6.5  #include <unistd.h>
     6.6  
     6.7 -#define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, getpagesize())
     6.8 +#define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, XC_PAGE_SIZE)
     6.9  
    6.10  /* size of the extra VMA area to map in attached pages. */
    6.11  #define BLKTAP_VMA_PAGES BLK_RING_SIZE
    6.12 @@ -74,10 +74,10 @@ static inline int BLKTAP_MODE_VALID(unsi
    6.13  		( arg == BLKTAP_MODE_INTERPOSE    ) );
    6.14  }
    6.15  
    6.16 -#define MAX_REQUESTS            64
    6.17 +#define MAX_REQUESTS            BLK_RING_SIZE
    6.18  
    6.19  #define BLKTAP_IOCTL_KICK 1
    6.20 -#define MAX_PENDING_REQS 64
    6.21 +#define MAX_PENDING_REQS	BLK_RING_SIZE
    6.22  #define BLKTAP_DEV_DIR   "/dev/xen"
    6.23  #define BLKTAP_DEV_NAME  "blktap"
    6.24  #define BLKTAP_DEV_MINOR 0
    6.25 @@ -199,7 +199,6 @@ int xs_fire_next_watch(struct xs_handle 
    6.26  
    6.27  
    6.28  /* Abitrary values, must match the underlying driver... */
    6.29 -#define MAX_PENDING_REQS 64
    6.30  #define MAX_TAP_DEV 100
    6.31  
    6.32  /* Accessing attached data page mappings */