[haiku-commits] haiku: hrev45877 - src/add-ons/kernel/drivers/disk/virtual/virtio_block

  • From: korli@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 18 Jul 2013 18:27:27 +0200 (CEST)

hrev45877 adds 2 changesets to branch 'master'
old head: 2f2f475b1d35e32e2afdefe624686d8ab5936c35
new head: f3b8787e915dfe31a80e10693b5cc854de92faeb
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=f3b8787+%5E2f2f475

----------------------------------------------------------------------------

9e88776: virtio_block: takes capacity change into account
  
  * allows live resizing.

f3b8787: virtio.h: remove trailing whitespaces.

                                   [ Jérôme Duval <jerome.duval@xxxxxxxxx> ]

----------------------------------------------------------------------------

2 files changed, 38 insertions(+), 4 deletions(-)
headers/private/virtio/virtio.h                  |  4 +--
.../disk/virtual/virtio_block/virtio_block.cpp   | 38 ++++++++++++++++++--

############################################################################

Commit:      9e88776c801a3a76f055ad935bd8ff1b0e48ce2e
URL:         http://cgit.haiku-os.org/haiku/commit/?id=9e88776
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Thu Jul 18 16:25:59 2013 UTC

virtio_block: takes capacity change into account

* allows live resizing.

----------------------------------------------------------------------------

diff --git 
a/src/add-ons/kernel/drivers/disk/virtual/virtio_block/virtio_block.cpp 
b/src/add-ons/kernel/drivers/disk/virtual/virtio_block/virtio_block.cpp
index 1e41a71..a1a6d1d 100644
--- a/src/add-ons/kernel/drivers/disk/virtual/virtio_block/virtio_block.cpp
+++ b/src/add-ons/kernel/drivers/disk/virtual/virtio_block/virtio_block.cpp
@@ -58,6 +58,7 @@ typedef struct {
        uint32                                  features;
        uint64                                  capacity;
        uint32                                  block_size;
+       status_t                                media_status;
 
        sem_id  sem_cb;
 } virtio_block_driver_info;
@@ -160,6 +161,29 @@ log2(uint32 x)
 
 
 static void
+virtio_block_config_callback(void* driverCookie)
+{
+       virtio_block_driver_info* info = 
(virtio_block_driver_info*)driverCookie;
+
+       status_t status = info->virtio->read_device_config(info->virtio_device, 
0,
+               &info->config, sizeof(struct virtio_blk_config));
+       if (status != B_OK)
+               return;
+
+       uint32 block_size = 512;
+       if ((info->features & VIRTIO_BLK_F_BLK_SIZE) != 0)
+               block_size = info->config.blk_size;
+       uint64 capacity = info->config.capacity * 512 / block_size;
+
+       if (block_size != info->block_size || capacity != info->capacity) {
+               virtio_block_set_capacity(info, capacity, block_size);
+               info->media_status = B_DEV_MEDIA_CHANGED;
+       }
+
+}
+
+
+static void
 virtio_block_callback(void* driverCookie, void* cookie)
 {
        virtio_block_driver_info* info = (virtio_block_driver_info*)cookie;
@@ -268,7 +292,8 @@ virtio_block_init_device(void* _info, void** _cookie)
                ERROR("queue allocation failed (%s)\n", strerror(status));
                return status;
        }
-       status = info->virtio->setup_interrupt(info->virtio_device, NULL, NULL);
+       status = info->virtio->setup_interrupt(info->virtio_device,
+               virtio_block_config_callback, info);
 
        *_cookie = info;
        return status;
@@ -398,6 +423,15 @@ virtio_block_ioctl(void* cookie, uint32 op, void* buffer, 
size_t length)
        TRACE("ioctl(op = %ld)\n", op);
 
        switch (op) {
+               case B_GET_MEDIA_STATUS:
+               {
+                       *(status_t *)buffer = info->media_status;
+                       info->media_status = B_OK;
+                       TRACE("B_GET_MEDIA_STATUS: 0x%08lx\n", *(status_t 
*)buffer);
+                       return B_OK;
+                       break;
+               }
+
                case B_GET_DEVICE_SIZE:
                {
                        size_t size = info->capacity * info->block_size;
@@ -555,6 +589,7 @@ virtio_block_init_driver(device_node *node, void **cookie)
 
        memset(info, 0, sizeof(*info));
 
+       info->media_status = B_OK;
        info->dma_resource = new(std::nothrow) DMAResource;
        if (info->dma_resource == NULL) {
                free(info);
@@ -659,4 +694,3 @@ module_info* modules[] = {
        (module_info*)&sVirtioBlockDevice,
        NULL
 };
-

############################################################################

Revision:    hrev45877
Commit:      f3b8787e915dfe31a80e10693b5cc854de92faeb
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f3b8787
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Thu Jul 18 16:27:01 2013 UTC

virtio.h: remove trailing whitespaces.

----------------------------------------------------------------------------

diff --git a/headers/private/virtio/virtio.h b/headers/private/virtio/virtio.h
index fffe0d7..0379242 100644
--- a/headers/private/virtio/virtio.h
+++ b/headers/private/virtio/virtio.h
@@ -81,7 +81,7 @@ typedef struct {
                size_t bufferSize);
        status_t (*write_device_config)(void* cookie, uint8 offset,
                const void* buffer, size_t bufferSize);
-       
+
        uint16  (*get_queue_ring_size)(void* cookie, uint16 queue);
        status_t (*setup_queue)(void* cookie, uint16 queue, phys_addr_t phy);
        status_t (*setup_interrupt)(void* cookie, uint16 queueCount);
@@ -95,7 +95,7 @@ typedef struct {
 
        status_t (*negociate_features)(virtio_device cookie, uint32 supported,
                uint32* negociated, const char* (*get_feature_name)(uint32));
-       
+
        status_t (*read_device_config)(virtio_device cookie, uint8 offset,
                void* buffer, size_t bufferSize);
        status_t (*write_device_config)(virtio_device cookie, uint8 offset,


Other related posts:

  • » [haiku-commits] haiku: hrev45877 - src/add-ons/kernel/drivers/disk/virtual/virtio_block - korli