Revision 5d12aa63

b/block.c
961 961
 * dictionary, it needs to use QINCREF() before calling bdrv_file_open.
962 962
 */
963 963
static int bdrv_file_open(BlockDriverState **pbs, const char *filename,
964
                          const char *reference, QDict *options, int flags,
965
                          Error **errp)
964
                          QDict *options, int flags, Error **errp)
966 965
{
967 966
    BlockDriverState *bs = NULL;
968 967
    BlockDriver *drv;
......
976 975
        options = qdict_new();
977 976
    }
978 977

  
979
    if (reference) {
980
        if (filename || qdict_size(options)) {
981
            error_setg(errp, "Cannot reference an existing block device with "
982
                       "additional options or a new filename");
983
            return -EINVAL;
984
        }
985
        QDECREF(options);
986

  
987
        bs = bdrv_lookup_bs(reference, reference, errp);
988
        if (!bs) {
989
            return -ENODEV;
990
        }
991
        bdrv_ref(bs);
992
        *pbs = bs;
993
        return 0;
994
    }
995

  
996 978
    bs = bdrv_new("");
997 979
    bs->options = options;
998 980
    options = qdict_clone_shallow(options);
......
1245 1227

  
1246 1228
    assert(pbs);
1247 1229

  
1248
    if (flags & BDRV_O_PROTOCOL) {
1249
        assert(!drv);
1250
        return bdrv_file_open(pbs, filename, reference, options,
1251
                              flags & ~BDRV_O_PROTOCOL, errp);
1252
    }
1253

  
1254 1230
    if (reference) {
1255 1231
        bool options_non_empty = options ? qdict_size(options) : false;
1256 1232
        QDECREF(options);
......
1276 1252
        return 0;
1277 1253
    }
1278 1254

  
1255
    if (flags & BDRV_O_PROTOCOL) {
1256
        assert(!drv);
1257
        return bdrv_file_open(pbs, filename, options, flags & ~BDRV_O_PROTOCOL,
1258
                              errp);
1259
    }
1260

  
1279 1261
    if (*pbs) {
1280 1262
        bs = *pbs;
1281 1263
    } else {

Also available in: Unified diff