Skip to content

Commit

Permalink
Merge pull request torvalds#238 from tavip/fix-237
Browse files Browse the repository at this point in the history
Fix block device capacity
  • Loading branch information
tavip authored Sep 18, 2016
2 parents 15bb4e7 + 6fc0b78 commit 4e4a8dd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
75 changes: 56 additions & 19 deletions tools/lkl/include/lkl_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern struct lkl_host_operations lkl_host_ops;
/**
* lkl_printf - print a message via the host print operation
*
* @fmt - printf like format string
* @fmt: printf like format string
*/
int lkl_printf(const char *fmt, ...);

Expand All @@ -30,24 +30,48 @@ struct iovec {

extern struct lkl_dev_blk_ops lkl_dev_blk_ops;

/**
* struct lkl_blk_req - block device request
*
* @type: type of request
* @prio: priority of request - currently unused
* @sector: offset in units 512 bytes for read / write requests
* @buf: an array of buffers to be used for read / write requests
* @count: the number of buffers
*/
struct lkl_blk_req {
#define LKL_DEV_BLK_TYPE_READ 0
#define LKL_DEV_BLK_TYPE_WRITE 1
#define LKL_DEV_BLK_TYPE_FLUSH 4
#define LKL_DEV_BLK_TYPE_FLUSH_OUT 5

struct lkl_blk_req {
unsigned int type;
unsigned int prio;
unsigned long long sector;
struct iovec *buf;
int count;
};

/**
* struct lkl_dev_blk_ops - block device host operations
*/
struct lkl_dev_blk_ops {
/**
* @get_capacity: returns the disk capacity in bytes
*
* @disk - the disk for which the capacity is requested;
* @res - pointer to receive the capacity, in bytes;
* @returns - 0 in case of success, negative value in case of error
*/
int (*get_capacity)(struct lkl_disk disk, unsigned long long *res);
#define LKL_DEV_BLK_STATUS_OK 0
#define LKL_DEV_BLK_STATUS_IOERR 1
#define LKL_DEV_BLK_STATUS_UNSUP 2
/**
* @request: issue a block request
*
* @disk - the disk the request is issued to;
* @req - a request described by &struct lkl_blk_req
*/
int (*request)(struct lkl_disk disk, struct lkl_blk_req *req);
};

Expand All @@ -56,21 +80,25 @@ struct lkl_netdev {
uint8_t has_vnet_hdr: 1;
};

/**
* struct lkl_dev_net_ops - network device host operations
*/
struct lkl_dev_net_ops {
/*
* Writes a L2 packet into the net device.
/**
* @tx: writes a L2 packet into the net device
*
* The data buffer can only hold 0 or 1 complete packets.
*
* @nd - pointer to the network device
* @iov - pointer to the buffer vector
* @nd - pointer to the network device;
* @iov - pointer to the buffer vector;
* @cnt - # of vectors in iov.
*
* @returns number of bytes transmitted
*/
int (*tx)(struct lkl_netdev *nd, struct iovec *iov, int cnt);

/*
* Reads a packet from the net device.
/**
* @rx: reads a packet from the net device.
*
* It must only read one complete packet if present.
*
Expand All @@ -80,6 +108,7 @@ struct lkl_dev_net_ops {
* @nd - pointer to the network device
* @iov - pointer to the buffer vector to store the packet
* @cnt - # of vectors in iov.
*
* @returns number of bytes read for success or < 0 if error
*/
int (*rx)(struct lkl_netdev *nd, struct iovec *iov, int cnt);
Expand All @@ -88,28 +117,36 @@ struct lkl_dev_net_ops {
#define LKL_DEV_NET_POLL_TX 2
#define LKL_DEV_NET_POLL_HUP 4

/*
* Polls a net device.
/**
* @poll: polls a net device
*
* Supports the following events: LKL_DEV_NET_POLL_RX (readable),
* LKL_DEV_NET_POLL_TX (writable) or LKL_DEV_NET_POLL_HUP (the close
* operations has been issued and we need to clean up). Blocks until one
* event is available.
* Supports the following events: LKL_DEV_NET_POLL_RX
* (readable), LKL_DEV_NET_POLL_TX (writable) or
* LKL_DEV_NET_POLL_HUP (the close operations has been issued
* and we need to clean up). Blocks until one event is
* available.
*
* @nd - pointer to the network device
*
* @returns - LKL_DEV_NET_POLL_RX, LKL_DEV_NET_POLL_TX,
* LKL_DEV_NET_POLL_HUP or a negative value for errors
*/
int (*poll)(struct lkl_netdev *nd);

/*
* Make poll wakeup and return LKL_DEV_NET_POLL_HUP.
/**
* @poll_hup: make poll wakeup and return LKL_DEV_NET_POLL_HUP
*
* @nd - pointer to the network device
*/
void (*poll_hup)(struct lkl_netdev *nd);

/*
* Frees a network device.
/**
* @free: frees a network device
*
* Implementation must release its resources and free the network device
* structure.
*
* @nd - pointer to the network device
*/
void (*free)(struct lkl_netdev *nd);
};
Expand Down
2 changes: 1 addition & 1 deletion tools/lkl/lib/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int lkl_disk_add(struct lkl_disk *disk)
ret = -LKL_ENOMEM;
goto out_free;
}
dev->config.capacity = capacity;
dev->config.capacity = capacity / 512;

ret = virtio_dev_setup(&dev->dev, 1, 32);
if (ret)
Expand Down

0 comments on commit 4e4a8dd

Please sign in to comment.