[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 10 of 21 RESEND] blktap3/drivers: Introduce back-end driver abstraction



This patch copies the back-end driver abstraction layer from blktap2, with
changes coming from blktap2.5.

Signed-off-by: Thanos Makatos <thanos.makatos@xxxxxxxxxx>

diff --git a/tools/blktap2/drivers/tapdisk-driver.c 
b/tools/blktap3/drivers/tapdisk-driver.c
copy from tools/blktap2/drivers/tapdisk-driver.c
copy to tools/blktap3/drivers/tapdisk-driver.c
--- a/tools/blktap2/drivers/tapdisk-driver.c
+++ b/tools/blktap3/drivers/tapdisk-driver.c
@@ -25,14 +25,49 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
 #include <stdlib.h>
+#include <stdio.h>
 
 #include "tapdisk-driver.h"
 #include "tapdisk-server.h"
 #include "tapdisk-disktype.h"
+#include "tapdisk-stats.h"
+
+static void
+tapdisk_driver_log_flush(td_driver_t * driver, const char *__caller)
+{
+    td_loglimit_t *rl = &driver->loglimit;
+
+    if (rl->dropped) {
+        tlog_syslog(LOG_WARNING,
+                    "%s: %s: %d messages suppressed",
+                    driver->name, __caller, rl->dropped);
+        rl->dropped = 0;
+    }
+}
+
+int tapdisk_driver_log_pass(td_driver_t * driver, const char *__caller)
+{
+    td_loglimit_t *rl = &driver->loglimit;
+    int dropping = rl->dropped;
+
+    if (tapdisk_loglimit_pass(rl)) {
+        tapdisk_driver_log_flush(driver, __caller);
+        return 1;
+    }
+
+    if (!dropping)
+        tlog_syslog(LOG_WARNING,
+                    "%s: %s: too many errors, dropped.",
+                    driver->name, __caller);
+
+    return 0;
+}
 
 td_driver_t *
-tapdisk_driver_allocate(int type, char *name, td_flag_t flags, int storage)
+tapdisk_driver_allocate(int type, const char *name,
+                                     td_flag_t flags)
 {
        int err;
        td_driver_t *driver;
@@ -52,7 +87,7 @@ tapdisk_driver_allocate(int type, char *
 
        driver->ops     = ops;
        driver->type    = type;
-       driver->storage = storage;
+    driver->storage = -1;
        driver->data    = calloc(1, ops->private_data_size);
        if (!driver->data)
                goto fail;
@@ -60,6 +95,9 @@ tapdisk_driver_allocate(int type, char *
        if (td_flag_test(flags, TD_OPEN_RDONLY))
                td_flag_set(driver->state, TD_DRIVER_RDONLY);
 
+    tapdisk_loglimit_init(&driver->loglimit, 16 /* msgs */ ,
+                          90 * 1000 /* ms */ );
+
        return driver;
 
 fail:
@@ -82,13 +120,16 @@ tapdisk_driver_free(td_driver_t *driver)
                EPRINTF("freeing open driver %s (state 0x%08x)\n",
                        driver->name, driver->state);
 
+    tapdisk_driver_log_flush(driver, __func__);
+
        free(driver->name);
        free(driver->data);
        free(driver);
 }
 
 void
-tapdisk_driver_queue_tiocb(td_driver_t *driver, struct tiocb *tiocb)
+tapdisk_driver_queue_tiocb(td_driver_t *driver __attribute__((unused)),
+        struct tiocb *tiocb)
 {
        tapdisk_server_queue_tiocb(tiocb);
 }
@@ -99,3 +140,21 @@ tapdisk_driver_debug(td_driver_t *driver
        if (driver->ops->td_debug)
                driver->ops->td_debug(driver);
 }
+
+void tapdisk_driver_stats(td_driver_t * driver, td_stats_t * st)
+{
+    const disk_info_t *info;
+
+    tapdisk_stats_field(st, "type", "d", driver->type);
+
+    info = tapdisk_disk_types[driver->type];
+    tapdisk_stats_field(st, "name", "s", info->name);
+
+    if (driver->ops->td_stats) {
+        tapdisk_stats_field(st, "status", "{");
+        driver->ops->td_stats(driver, st);
+        tapdisk_stats_leave(st, '}');
+    } else
+        tapdisk_stats_field(st, "status", NULL);
+
+}
diff --git a/tools/blktap2/drivers/tapdisk-driver.h 
b/tools/blktap3/drivers/tapdisk-driver.h
copy from tools/blktap2/drivers/tapdisk-driver.h
copy to tools/blktap3/drivers/tapdisk-driver.h
--- a/tools/blktap2/drivers/tapdisk-driver.h
+++ b/tools/blktap3/drivers/tapdisk-driver.h
@@ -31,6 +31,7 @@
 #include "tapdisk.h"
 #include "scheduler.h"
 #include "tapdisk-queue.h"
+#include "tapdisk-loglimit.h"
 
 #define TD_DRIVER_OPEN               0x0001
 #define TD_DRIVER_RDONLY             0x0002
@@ -49,14 +50,19 @@ struct td_driver_handle {
        void                        *data;
        const struct tap_disk       *ops;
 
-       struct list_head             next;
+    td_loglimit_t loglimit;
+     TAILQ_ENTRY(td_driver_handle) next;
 };
 
-td_driver_t *tapdisk_driver_allocate(int, char *, td_flag_t, int);
+td_driver_t *tapdisk_driver_allocate(int, const char *, td_flag_t);
 void tapdisk_driver_free(td_driver_t *);
 
 void tapdisk_driver_queue_tiocb(td_driver_t *, struct tiocb *);
 
 void tapdisk_driver_debug(td_driver_t *);
 
+void tapdisk_driver_stats(td_driver_t *, td_stats_t *);
+
+int tapdisk_driver_log_pass(td_driver_t *, const char *caller);
+
 #endif

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.