]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - Documentation/lguest/lguest.c
Merge branch 'v2.6.36-rc8' into for-2.6.37/barrier
[net-next-2.6.git] / Documentation / lguest / lguest.c
index e9ce3c5545145f9b2c683c26690c0159b6c437fc..dc73bc54cc4e4cacb57fcb72289f88f5d99ef7e0 100644 (file)
 #include <limits.h>
 #include <stddef.h>
 #include <signal.h>
-#include "linux/lguest_launcher.h"
-#include "linux/virtio_config.h"
-#include "linux/virtio_net.h"
-#include "linux/virtio_blk.h"
-#include "linux/virtio_console.h"
-#include "linux/virtio_rng.h"
-#include "linux/virtio_ring.h"
-#include "asm/bootparam.h"
+#include <linux/virtio_config.h>
+#include <linux/virtio_net.h>
+#include <linux/virtio_blk.h>
+#include <linux/virtio_console.h>
+#include <linux/virtio_rng.h>
+#include <linux/virtio_ring.h>
+#include <asm/bootparam.h>
+#include "../../include/linux/lguest_launcher.h"
 /*L:110
  * We can ignore the 42 include files we need for this program, but I do want
  * to draw attention to the use of kernel-style types.
@@ -1447,14 +1447,15 @@ static void add_to_bridge(int fd, const char *if_name, const char *br_name)
 static void configure_device(int fd, const char *tapif, u32 ipaddr)
 {
        struct ifreq ifr;
-       struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr;
+       struct sockaddr_in sin;
 
        memset(&ifr, 0, sizeof(ifr));
        strcpy(ifr.ifr_name, tapif);
 
        /* Don't read these incantations.  Just cut & paste them like I did! */
-       sin->sin_family = AF_INET;
-       sin->sin_addr.s_addr = htonl(ipaddr);
+       sin.sin_family = AF_INET;
+       sin.sin_addr.s_addr = htonl(ipaddr);
+       memcpy(&ifr.ifr_addr, &sin, sizeof(sin));
        if (ioctl(fd, SIOCSIFADDR, &ifr) != 0)
                err(1, "Setting %s interface address", tapif);
        ifr.ifr_flags = IFF_UP;
@@ -1638,15 +1639,6 @@ static void blk_request(struct virtqueue *vq)
         */
        off = out->sector * 512;
 
-       /*
-        * The block device implements "barriers", where the Guest indicates
-        * that it wants all previous writes to occur before this write.  We
-        * don't have a way of asking our kernel to do a barrier, so we just
-        * synchronize all the data in the file.  Pretty poor, no?
-        */
-       if (out->type & VIRTIO_BLK_T_BARRIER)
-               fdatasync(vblk->fd);
-
        /*
         * In general the virtio block driver is allowed to try SCSI commands.
         * It'd be nice if we supported eject, for example, but we don't.
@@ -1679,6 +1671,13 @@ static void blk_request(struct virtqueue *vq)
                        /* Die, bad Guest, die. */
                        errx(1, "Write past end %llu+%u", off, ret);
                }
+
+               wlen = sizeof(*in);
+               *in = (ret >= 0 ? VIRTIO_BLK_S_OK : VIRTIO_BLK_S_IOERR);
+       } else if (out->type & VIRTIO_BLK_T_FLUSH) {
+               /* Flush */
+               ret = fdatasync(vblk->fd);
+               verbose("FLUSH fdatasync: %i\n", ret);
                wlen = sizeof(*in);
                *in = (ret >= 0 ? VIRTIO_BLK_S_OK : VIRTIO_BLK_S_IOERR);
        } else {
@@ -1702,15 +1701,6 @@ static void blk_request(struct virtqueue *vq)
                }
        }
 
-       /*
-        * OK, so we noted that it was pretty poor to use an fdatasync as a
-        * barrier.  But Christoph Hellwig points out that we need a sync
-        * *afterwards* as well: "Barriers specify no reordering to the front
-        * or the back."  And Jens Axboe confirmed it, so here we are:
-        */
-       if (out->type & VIRTIO_BLK_T_BARRIER)
-               fdatasync(vblk->fd);
-
        /* Finished that request. */
        add_used(vq, head, wlen);
 }
@@ -1735,8 +1725,8 @@ static void setup_block_file(const char *filename)
        vblk->fd = open_or_die(filename, O_RDWR|O_LARGEFILE);
        vblk->len = lseek64(vblk->fd, 0, SEEK_END);
 
-       /* We support barriers. */
-       add_feature(dev, VIRTIO_BLK_F_BARRIER);
+       /* We support FLUSH. */
+       add_feature(dev, VIRTIO_BLK_F_FLUSH);
 
        /* Tell Guest how many sectors this device has. */
        conf.capacity = cpu_to_le64(vblk->len / 512);