void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,

                        Error **errp)

{

    BlockDriverState *bs;

    NBDExport *exp;

    NBDCloseNotifier *n;



    if (server_fd == -1) {

        error_setg(errp, "NBD server not running");

        return;

    }



    if (nbd_export_find(device)) {

        error_setg(errp, "NBD server already exporting device '%s'", device);

        return;

    }



    bs = bdrv_find(device);

    if (!bs) {

        error_set(errp, QERR_DEVICE_NOT_FOUND, device);

        return;

    }

    if (!bdrv_is_inserted(bs)) {

        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);

        return;

    }



    if (!has_writable) {

        writable = false;

    }

    if (bdrv_is_read_only(bs)) {

        writable = false;

    }



    exp = nbd_export_new(bs, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY, NULL);



    nbd_export_set_name(exp, device);



    n = g_malloc0(sizeof(NBDCloseNotifier));

    n->n.notify = nbd_close_notifier;

    n->exp = exp;

    bdrv_add_close_notifier(bs, &n->n);

    QTAILQ_INSERT_TAIL(&close_notifiers, n, next);

}

void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,

                        Error **errp)

{

    BlockDriverState *bs;

    NBDExport *exp;

    NBDCloseNotifier *n;



    if (server_fd == -1) {

        error_setg(errp, "NBD server not running");

        return;

    }



    if (nbd_export_find(device)) {

        error_setg(errp, "NBD server already exporting device '%s'", device);

        return;

    }



    bs = bdrv_find(device);

    if (!bs) {

        error_set(errp, QERR_DEVICE_NOT_FOUND, device);

        return;

    }

    if (!bdrv_is_inserted(bs)) {

        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);

        return;

    }



    if (!has_writable) {

        writable = false;

    }

    if (bdrv_is_read_only(bs)) {

        writable = false;

    }



    exp = nbd_export_new(bs, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY, NULL);



    nbd_export_set_name(exp, device);



    n = g_malloc0(sizeof(NBDCloseNotifier));

    n->n.notify = nbd_close_notifier;

    n->exp = exp;

    bdrv_add_close_notifier(bs, &n->n);

    QTAILQ_INSERT_TAIL(&close_notifiers, n, next);

}

    n = g_malloc0(sizeof(NBDCloseNotifier));
void FUNC_0(const char *VAR_0, bool VAR_1, bool VAR_2,

                        Error **VAR_3)

{

    BlockDriverState *bs;

    NBDExport *exp;

    NBDCloseNotifier *n;



    if (server_fd == -1) {

        error_setg(VAR_3, "NBD server not running");

        return;

    }



    if (nbd_export_find(VAR_0)) {

        error_setg(VAR_3, "NBD server already exporting VAR_0 '%s'", VAR_0);

        return;

    }



    bs = bdrv_find(VAR_0);

    if (!bs) {

        error_set(VAR_3, QERR_DEVICE_NOT_FOUND, VAR_0);

        return;

    }

    if (!bdrv_is_inserted(bs)) {

        error_set(VAR_3, QERR_DEVICE_HAS_NO_MEDIUM, VAR_0);

        return;

    }



    if (!VAR_1) {

        VAR_2 = false;

    }

    if (bdrv_is_read_only(bs)) {

        VAR_2 = false;

    }



    exp = nbd_export_new(bs, 0, -1, VAR_2 ? 0 : NBD_FLAG_READ_ONLY, NULL);



    nbd_export_set_name(exp, VAR_0);



    n = g_malloc0(sizeof(NBDCloseNotifier));

    n->n.notify = nbd_close_notifier;

    n->exp = exp;

    bdrv_add_close_notifier(bs, &n->n);

    QTAILQ_INSERT_TAIL(&close_notifiers, n, next);

}

void FUNC_0(const char *VAR_0, bool VAR_1, bool VAR_2,
Error **VAR_3)
{ BlockDriverState *bs; NBDExport *exp; NBDCloseNotifier *n; if (server_fd == -1) { error_setg(VAR_3, "NBD server not running"); return; } if (nbd_export_find(VAR_0)) { error_setg(VAR_3, "NBD server already exporting VAR_0 '%s'", VAR_0); return; } bs = bdrv_find(VAR_0); if (!bs) { error_set(VAR_3, QERR_DEVICE_NOT_FOUND, VAR_0); return; } if (!bdrv_is_inserted(bs)) { error_set(VAR_3, QERR_DEVICE_HAS_NO_MEDIUM, VAR_0); return; } if (!VAR_1) { VAR_2 = false; } if (bdrv_is_read_only(bs)) { VAR_2 = false; } exp = nbd_export_new(bs, 0, -1, VAR_2 ? 0 : NBD_FLAG_READ_ONLY, NULL); nbd_export_set_name(exp, VAR_0); n = g_malloc0(sizeof(NBDCloseNotifier)); n->n.notify = nbd_close_notifier; n->exp = exp; bdrv_add_close_notifier(bs, &n->n); QTAILQ_INSERT_TAIL(&close_notifiers, n, next); }