Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lguest and virtio: cleanup struct definitions to Linux style.

I've been doing this for years, and akpm picked me up on it about 12
months ago. lguest partly serves as example code, so let's do it Right.

Also, remove two unused fields in struct vblk_info in the example launcher.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Ingo Molnar <mingo@redhat.com>

+19 -44
+5 -16
Documentation/lguest/lguest.c
··· 93 93 static unsigned int __thread cpu_id; 94 94 95 95 /* This is our list of devices. */ 96 - struct device_list 97 - { 96 + struct device_list { 98 97 /* Counter to assign interrupt numbers. */ 99 98 unsigned int next_irq; 100 99 ··· 113 114 static struct device_list devices; 114 115 115 116 /* The device structure describes a single device. */ 116 - struct device 117 - { 117 + struct device { 118 118 /* The linked-list pointer. */ 119 119 struct device *next; 120 120 ··· 138 140 }; 139 141 140 142 /* The virtqueue structure describes a queue attached to a device. */ 141 - struct virtqueue 142 - { 143 + struct virtqueue { 143 144 struct virtqueue *next; 144 145 145 146 /* Which device owns me. */ ··· 776 779 * 777 780 * We associate some data with the console for our exit hack. 778 781 */ 779 - struct console_abort 780 - { 782 + struct console_abort { 781 783 /* How many times have they hit ^C? */ 782 784 int count; 783 785 /* When did they start? */ ··· 1566 1570 /*:*/ 1567 1571 1568 1572 /* This hangs off device->priv. */ 1569 - struct vblk_info 1570 - { 1573 + struct vblk_info { 1571 1574 /* The size of the file. */ 1572 1575 off64_t len; 1573 1576 1574 1577 /* The file descriptor for the file. */ 1575 1578 int fd; 1576 1579 1577 - /* IO thread listens on this file descriptor [0]. */ 1578 - int workpipe[2]; 1579 - 1580 - /* IO thread writes to this file descriptor to mark it done, then 1581 - * Launcher triggers interrupt to Guest. */ 1582 - int done_fd; 1583 1580 }; 1584 1581 1585 1582 /*L:210
+3 -6
drivers/lguest/lg.h
··· 16 16 void free_pagetables(void); 17 17 int init_pagetables(struct page **switcher_page, unsigned int pages); 18 18 19 - struct pgdir 20 - { 19 + struct pgdir { 21 20 unsigned long gpgdir; 22 21 pgd_t *pgdir; 23 22 }; 24 23 25 24 /* We have two pages shared with guests, per cpu. */ 26 - struct lguest_pages 27 - { 25 + struct lguest_pages { 28 26 /* This is the stack page mapped rw in guest */ 29 27 char spare[PAGE_SIZE - sizeof(struct lguest_regs)]; 30 28 struct lguest_regs regs; ··· 87 89 }; 88 90 89 91 /* The private info the thread maintains about the guest. */ 90 - struct lguest 91 - { 92 + struct lguest { 92 93 struct lguest_data __user *lguest_data; 93 94 struct lg_cpu cpus[NR_CPUS]; 94 95 unsigned int nr_cpus;
+1 -2
drivers/lguest/lguest_device.c
··· 207 207 */ 208 208 209 209 /*D:140 This is the information we remember about each virtqueue. */ 210 - struct lguest_vq_info 211 - { 210 + struct lguest_vq_info { 212 211 /* A copy of the information contained in the device config. */ 213 212 struct lguest_vqconfig config; 214 213
+1 -2
include/linux/lguest.h
··· 18 18 * lguest_data". Once the Guest's initialization hypercall tells the Host where 19 19 * this is, the Guest and Host both publish information in it. 20 20 :*/ 21 - struct lguest_data 22 - { 21 + struct lguest_data { 23 22 /* 24 23 * 512 == enabled (same as eflags in normal hardware). The Guest 25 24 * changes interrupts so often that a hypercall is too slow.
+2 -4
include/linux/virtio_blk.h
··· 20 20 21 21 #define VIRTIO_BLK_ID_BYTES (sizeof(__u16[256])) /* IDENTIFY DATA */ 22 22 23 - struct virtio_blk_config 24 - { 23 + struct virtio_blk_config { 25 24 /* The capacity (in 512-byte sectors). */ 26 25 __u64 capacity; 27 26 /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ ··· 49 50 #define VIRTIO_BLK_T_BARRIER 0x80000000 50 51 51 52 /* This is the first element of the read scatter-gather list. */ 52 - struct virtio_blk_outhdr 53 - { 53 + struct virtio_blk_outhdr { 54 54 /* VIRTIO_BLK_T* */ 55 55 __u32 type; 56 56 /* io priority. */
+1 -2
include/linux/virtio_config.h
··· 79 79 * the dev->feature bits if it wants. 80 80 */ 81 81 typedef void vq_callback_t(struct virtqueue *); 82 - struct virtio_config_ops 83 - { 82 + struct virtio_config_ops { 84 83 void (*get)(struct virtio_device *vdev, unsigned offset, 85 84 void *buf, unsigned len); 86 85 void (*set)(struct virtio_device *vdev, unsigned offset,
+2 -4
include/linux/virtio_net.h
··· 31 31 32 32 #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ 33 33 34 - struct virtio_net_config 35 - { 34 + struct virtio_net_config { 36 35 /* The config defining mac address (if VIRTIO_NET_F_MAC) */ 37 36 __u8 mac[6]; 38 37 /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */ ··· 40 41 41 42 /* This is the first element of the scatter-gather list. If you don't 42 43 * specify GSO or CSUM features, you can simply ignore the header. */ 43 - struct virtio_net_hdr 44 - { 44 + struct virtio_net_hdr { 45 45 #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 // Use csum_start, csum_offset 46 46 __u8 flags; 47 47 #define VIRTIO_NET_HDR_GSO_NONE 0 // Not a GSO frame
+4 -8
include/linux/virtio_ring.h
··· 30 30 #define VIRTIO_RING_F_INDIRECT_DESC 28 31 31 32 32 /* Virtio ring descriptors: 16 bytes. These can chain together via "next". */ 33 - struct vring_desc 34 - { 33 + struct vring_desc { 35 34 /* Address (guest-physical). */ 36 35 __u64 addr; 37 36 /* Length. */ ··· 41 42 __u16 next; 42 43 }; 43 44 44 - struct vring_avail 45 - { 45 + struct vring_avail { 46 46 __u16 flags; 47 47 __u16 idx; 48 48 __u16 ring[]; 49 49 }; 50 50 51 51 /* u32 is used here for ids for padding reasons. */ 52 - struct vring_used_elem 53 - { 52 + struct vring_used_elem { 54 53 /* Index of start of used descriptor chain. */ 55 54 __u32 id; 56 55 /* Total length of the descriptor chain which was used (written to) */ 57 56 __u32 len; 58 57 }; 59 58 60 - struct vring_used 61 - { 59 + struct vring_used { 62 60 __u16 flags; 63 61 __u16 idx; 64 62 struct vring_used_elem ring[];