Commit 1842f23c05b6a866be831aa60bc8a8731c58ddd0

Authored by Rusty Russell
1 parent a91d74a3c4

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>

Showing 8 changed files with 19 additions and 44 deletions Side-by-side Diff

Documentation/lguest/lguest.c
... ... @@ -93,8 +93,7 @@
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  
... ... @@ -114,8 +113,7 @@
114 113 static struct device_list devices;
115 114  
116 115 /* The device structure describes a single device. */
117   -struct device
118   -{
  116 +struct device {
119 117 /* The linked-list pointer. */
120 118 struct device *next;
121 119  
... ... @@ -140,8 +138,7 @@
140 138 };
141 139  
142 140 /* The virtqueue structure describes a queue attached to a device. */
143   -struct virtqueue
144   -{
  141 +struct virtqueue {
145 142 struct virtqueue *next;
146 143  
147 144 /* Which device owns me. */
... ... @@ -779,8 +776,7 @@
779 776 *
780 777 * We associate some data with the console for our exit hack.
781 778 */
782   -struct console_abort
783   -{
  779 +struct console_abort {
784 780 /* How many times have they hit ^C? */
785 781 int count;
786 782 /* When did they start? */
787 783  
... ... @@ -1570,20 +1566,13 @@
1570 1566 /*:*/
1571 1567  
1572 1568 /* This hangs off device->priv. */
1573   -struct vblk_info
1574   -{
  1569 +struct vblk_info {
1575 1570 /* The size of the file. */
1576 1571 off64_t len;
1577 1572  
1578 1573 /* The file descriptor for the file. */
1579 1574 int fd;
1580 1575  
1581   - /* IO thread listens on this file descriptor [0]. */
1582   - int workpipe[2];
1583   -
1584   - /* IO thread writes to this file descriptor to mark it done, then
1585   - * Launcher triggers interrupt to Guest. */
1586   - int done_fd;
1587 1576 };
1588 1577  
1589 1578 /*L:210
... ... @@ -16,15 +16,13 @@
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;
... ... @@ -89,8 +87,7 @@
89 87 };
90 88  
91 89 /* The private info the thread maintains about the guest. */
92   -struct lguest
93   -{
  90 +struct lguest {
94 91 struct lguest_data __user *lguest_data;
95 92 struct lg_cpu cpus[NR_CPUS];
96 93 unsigned int nr_cpus;
drivers/lguest/lguest_device.c
... ... @@ -207,8 +207,7 @@
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  
include/linux/lguest.h
... ... @@ -18,8 +18,7 @@
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.
include/linux/virtio_blk.h
... ... @@ -20,8 +20,7 @@
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) */
... ... @@ -50,8 +49,7 @@
50 49 #define VIRTIO_BLK_T_BARRIER 0x80000000
51 50  
52 51 /* This is the first element of the read scatter-gather list. */
53   -struct virtio_blk_outhdr
54   -{
  52 +struct virtio_blk_outhdr {
55 53 /* VIRTIO_BLK_T* */
56 54 __u32 type;
57 55 /* io priority. */
include/linux/virtio_config.h
... ... @@ -79,8 +79,7 @@
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,
include/linux/virtio_net.h
... ... @@ -31,8 +31,7 @@
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 */
... ... @@ -41,8 +40,7 @@
41 40  
42 41 /* This is the first element of the scatter-gather list. If you don't
43 42 * specify GSO or CSUM features, you can simply ignore the header. */
44   -struct virtio_net_hdr
45   -{
  43 +struct virtio_net_hdr {
46 44 #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 // Use csum_start, csum_offset
47 45 __u8 flags;
48 46 #define VIRTIO_NET_HDR_GSO_NONE 0 // Not a GSO frame
include/linux/virtio_ring.h
... ... @@ -30,8 +30,7 @@
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. */
38 37  
39 38  
... ... @@ -42,24 +41,21 @@
42 41 __u16 next;
43 42 };
44 43  
45   -struct vring_avail
46   -{
  44 +struct vring_avail {
47 45 __u16 flags;
48 46 __u16 idx;
49 47 __u16 ring[];
50 48 };
51 49  
52 50 /* u32 is used here for ids for padding reasons. */
53   -struct vring_used_elem
54   -{
  51 +struct vring_used_elem {
55 52 /* Index of start of used descriptor chain. */
56 53 __u32 id;
57 54 /* Total length of the descriptor chain which was used (written to) */
58 55 __u32 len;
59 56 };
60 57  
61   -struct vring_used
62   -{
  58 +struct vring_used {
63 59 __u16 flags;
64 60 __u16 idx;
65 61 struct vring_used_elem ring[];