qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qom: Make functions taking Error ** return bool, not void

See recent commit "error: Document Error API usage rules" for
rationale.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-28-armbru@redhat.com>

+122 -62
+31 -11
include/qom/object.h
··· 703 703 Error **errp, 704 704 va_list vargs); 705 705 706 - void object_apply_global_props(Object *obj, const GPtrArray *props, 706 + bool object_apply_global_props(Object *obj, const GPtrArray *props, 707 707 Error **errp); 708 708 void object_set_machine_compat_props(GPtrArray *compat_props); 709 709 void object_set_accelerator_compat_props(GPtrArray *compat_props); ··· 798 798 * strings. The propname of %NULL indicates the end of the property list. 799 799 * If the object implements the user creatable interface, the object will 800 800 * be marked complete once all the properties have been processed. 801 + * 802 + * Returns: %true on success, %false on failure. 801 803 */ 802 - void object_initialize_child_with_props(Object *parentobj, 804 + bool object_initialize_child_with_props(Object *parentobj, 803 805 const char *propname, 804 806 void *childobj, size_t size, const char *type, 805 807 Error **errp, ...) QEMU_SENTINEL; ··· 815 817 * @vargs: list of property names and values 816 818 * 817 819 * See object_initialize_child() for documentation. 820 + * 821 + * Returns: %true on success, %false on failure. 818 822 */ 819 - void object_initialize_child_with_propsv(Object *parentobj, 823 + bool object_initialize_child_with_propsv(Object *parentobj, 820 824 const char *propname, 821 825 void *childobj, size_t size, const char *type, 822 826 Error **errp, va_list vargs); ··· 1209 1213 * @errp: returns an error if this function fails 1210 1214 * 1211 1215 * Reads a property from a object. 1216 + * 1217 + * Returns: %true on success, %false on failure. 1212 1218 */ 1213 - void object_property_get(Object *obj, const char *name, Visitor *v, 1219 + bool object_property_get(Object *obj, const char *name, Visitor *v, 1214 1220 Error **errp); 1215 1221 1216 1222 /** ··· 1220 1226 * @errp: returns an error if this function fails 1221 1227 * 1222 1228 * Writes a string value to a property. 1229 + * 1230 + * Returns: %true on success, %false on failure. 1223 1231 */ 1224 - void object_property_set_str(Object *obj, const char *name, 1232 + bool object_property_set_str(Object *obj, const char *name, 1225 1233 const char *value, Error **errp); 1226 1234 1227 1235 /** ··· 1249 1257 * <code>OBJ_PROP_LINK_STRONG</code> bit, the old target object is 1250 1258 * unreferenced, and a reference is added to the new target object. 1251 1259 * 1260 + * Returns: %true on success, %false on failure. 1252 1261 */ 1253 - void object_property_set_link(Object *obj, const char *name, 1262 + bool object_property_set_link(Object *obj, const char *name, 1254 1263 Object *value, Error **errp); 1255 1264 1256 1265 /** ··· 1273 1282 * @errp: returns an error if this function fails 1274 1283 * 1275 1284 * Writes a bool value to a property. 1285 + * 1286 + * Returns: %true on success, %false on failure. 1276 1287 */ 1277 - void object_property_set_bool(Object *obj, const char *name, 1288 + bool object_property_set_bool(Object *obj, const char *name, 1278 1289 bool value, Error **errp); 1279 1290 1280 1291 /** ··· 1296 1307 * @errp: returns an error if this function fails 1297 1308 * 1298 1309 * Writes an integer value to a property. 1310 + * 1311 + * Returns: %true on success, %false on failure. 1299 1312 */ 1300 - void object_property_set_int(Object *obj, const char *name, 1313 + bool object_property_set_int(Object *obj, const char *name, 1301 1314 int64_t value, Error **errp); 1302 1315 1303 1316 /** ··· 1319 1332 * @errp: returns an error if this function fails 1320 1333 * 1321 1334 * Writes an unsigned integer value to a property. 1335 + * 1336 + * Returns: %true on success, %false on failure. 1322 1337 */ 1323 - void object_property_set_uint(Object *obj, const char *name, 1338 + bool object_property_set_uint(Object *obj, const char *name, 1324 1339 uint64_t value, Error **errp); 1325 1340 1326 1341 /** ··· 1359 1374 * @errp: returns an error if this function fails 1360 1375 * 1361 1376 * Writes a property to a object. 1377 + * 1378 + * Returns: %true on success, %false on failure. 1362 1379 */ 1363 - void object_property_set(Object *obj, const char *name, Visitor *v, 1380 + bool object_property_set(Object *obj, const char *name, Visitor *v, 1364 1381 Error **errp); 1365 1382 1366 1383 /** ··· 1371 1388 * @errp: returns an error if this function fails 1372 1389 * 1373 1390 * Parses a string and writes the result into a property of an object. 1391 + * 1392 + * Returns: %true on success, %false on failure. 1374 1393 */ 1375 - void object_property_parse(Object *obj, const char *name, 1394 + bool object_property_parse(Object *obj, const char *name, 1376 1395 const char *string, Error **errp); 1377 1396 1378 1397 /** ··· 1815 1834 * 1816 1835 * Set an object property's description. 1817 1836 * 1837 + * Returns: %true on success, %false on failure. 1818 1838 */ 1819 1839 void object_property_set_description(Object *obj, const char *name, 1820 1840 const char *description);
+9 -3
include/qom/object_interfaces.h
··· 57 57 * Wrapper to call complete() method if one of types it's inherited 58 58 * from implements USER_CREATABLE interface, otherwise the call does 59 59 * nothing. 60 + * 61 + * Returns: %true on success, %false on failure. 60 62 */ 61 - void user_creatable_complete(UserCreatable *uc, Error **errp); 63 + bool user_creatable_complete(UserCreatable *uc, Error **errp); 62 64 63 65 /** 64 66 * user_creatable_can_be_deleted: ··· 100 102 * @qdict. The object type is taken from the QDict key 'qom-type', its 101 103 * ID from the key 'id'. The remaining entries in @qdict are used to 102 104 * initialize the object properties. 105 + * 106 + * Returns: %true on success, %false on failure. 103 107 */ 104 - void user_creatable_add_dict(QDict *qdict, bool keyval, Error **errp); 108 + bool user_creatable_add_dict(QDict *qdict, bool keyval, Error **errp); 105 109 106 110 /** 107 111 * user_creatable_add_opts: ··· 167 171 * 168 172 * Delete an instance of the user creatable object identified 169 173 * by @id. 174 + * 175 + * Returns: %true on success, %false on failure. 170 176 */ 171 - void user_creatable_del(const char *id, Error **errp); 177 + bool user_creatable_del(const char *id, Error **errp); 172 178 173 179 /** 174 180 * user_creatable_cleanup:
+3 -1
include/qom/qom-qobject.h
··· 33 33 * @errp: returns an error if this function fails 34 34 * 35 35 * Writes a property to a object. 36 + * 37 + * Returns: %true on success, %false on failure. 36 38 */ 37 - void object_property_set_qobject(Object *obj, 39 + bool object_property_set_qobject(Object *obj, 38 40 const char *name, struct QObject *value, 39 41 struct Error **errp); 40 42
+62 -37
qom/object.c
··· 385 385 } 386 386 } 387 387 388 - void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp) 388 + bool object_apply_global_props(Object *obj, const GPtrArray *props, 389 + Error **errp) 389 390 { 390 391 int i; 391 392 392 393 if (!props) { 393 - return; 394 + return true; 394 395 } 395 396 396 397 for (i = 0; i < props->len; i++) { ··· 415 416 */ 416 417 if (errp) { 417 418 error_propagate(errp, err); 418 - return; 419 + return false; 419 420 } else { 420 421 warn_report_err(err); 421 422 } 422 423 } 423 424 } 425 + 426 + return true; 424 427 } 425 428 426 429 /* ··· 524 527 object_initialize_with_type(data, size, type); 525 528 } 526 529 527 - void object_initialize_child_with_props(Object *parentobj, 528 - const char *propname, 529 - void *childobj, size_t size, const char *type, 530 - Error **errp, ...) 530 + bool object_initialize_child_with_props(Object *parentobj, 531 + const char *propname, 532 + void *childobj, size_t size, 533 + const char *type, 534 + Error **errp, ...) 531 535 { 532 536 va_list vargs; 537 + bool ok; 533 538 534 539 va_start(vargs, errp); 535 - object_initialize_child_with_propsv(parentobj, propname, 536 - childobj, size, type, errp, vargs); 540 + ok = object_initialize_child_with_propsv(parentobj, propname, 541 + childobj, size, type, errp, 542 + vargs); 537 543 va_end(vargs); 544 + return ok; 538 545 } 539 546 540 - void object_initialize_child_with_propsv(Object *parentobj, 541 - const char *propname, 542 - void *childobj, size_t size, const char *type, 543 - Error **errp, va_list vargs) 547 + bool object_initialize_child_with_propsv(Object *parentobj, 548 + const char *propname, 549 + void *childobj, size_t size, 550 + const char *type, 551 + Error **errp, va_list vargs) 544 552 { 545 553 Error *local_err = NULL; 554 + bool ok = false; 546 555 Object *obj; 547 556 UserCreatable *uc; 548 557 ··· 564 573 } 565 574 } 566 575 576 + ok = true; 577 + 567 578 out: 568 579 /* 569 580 * We want @obj's reference to be 1 on success, 0 on failure. ··· 576 587 object_unref(obj); 577 588 578 589 error_propagate(errp, local_err); 590 + return ok; 579 591 } 580 592 581 593 void object_initialize_child_internal(Object *parent, ··· 1312 1324 g_hash_table_remove(obj->properties, name); 1313 1325 } 1314 1326 1315 - void object_property_get(Object *obj, const char *name, Visitor *v, 1327 + bool object_property_get(Object *obj, const char *name, Visitor *v, 1316 1328 Error **errp) 1317 1329 { 1330 + Error *err = NULL; 1318 1331 ObjectProperty *prop = object_property_find(obj, name, errp); 1332 + 1319 1333 if (prop == NULL) { 1320 - return; 1334 + return false; 1321 1335 } 1322 1336 1323 1337 if (!prop->get) { 1324 1338 error_setg(errp, QERR_PERMISSION_DENIED); 1325 - } else { 1326 - prop->get(obj, v, name, prop->opaque, errp); 1339 + return false; 1327 1340 } 1341 + prop->get(obj, v, name, prop->opaque, &err); 1342 + error_propagate(errp, err); 1343 + return !err; 1328 1344 } 1329 1345 1330 - void object_property_set(Object *obj, const char *name, Visitor *v, 1346 + bool object_property_set(Object *obj, const char *name, Visitor *v, 1331 1347 Error **errp) 1332 1348 { 1349 + Error *err = NULL; 1333 1350 ObjectProperty *prop = object_property_find(obj, name, errp); 1351 + 1334 1352 if (prop == NULL) { 1335 - return; 1353 + return false; 1336 1354 } 1337 1355 1338 1356 if (!prop->set) { 1339 1357 error_setg(errp, QERR_PERMISSION_DENIED); 1340 - } else { 1341 - prop->set(obj, v, name, prop->opaque, errp); 1358 + return false; 1342 1359 } 1360 + prop->set(obj, v, name, prop->opaque, &err); 1361 + error_propagate(errp, err); 1362 + return !err; 1343 1363 } 1344 1364 1345 - void object_property_set_str(Object *obj, const char *name, 1365 + bool object_property_set_str(Object *obj, const char *name, 1346 1366 const char *value, Error **errp) 1347 1367 { 1348 1368 QString *qstr = qstring_from_str(value); 1349 - object_property_set_qobject(obj, name, QOBJECT(qstr), errp); 1369 + bool ok = object_property_set_qobject(obj, name, QOBJECT(qstr), errp); 1350 1370 1351 1371 qobject_unref(qstr); 1372 + return ok; 1352 1373 } 1353 1374 1354 1375 char *object_property_get_str(Object *obj, const char *name, ··· 1370 1391 return retval; 1371 1392 } 1372 1393 1373 - void object_property_set_link(Object *obj, const char *name, 1394 + bool object_property_set_link(Object *obj, const char *name, 1374 1395 Object *value, Error **errp) 1375 1396 { 1397 + g_autofree char *path = NULL; 1398 + 1376 1399 if (value) { 1377 - char *path = object_get_canonical_path(value); 1378 - object_property_set_str(obj, name, path, errp); 1379 - g_free(path); 1380 - } else { 1381 - object_property_set_str(obj, name, "", errp); 1400 + path = object_get_canonical_path(value); 1382 1401 } 1402 + return object_property_set_str(obj, name, path ?: "", errp); 1383 1403 } 1384 1404 1385 1405 Object *object_property_get_link(Object *obj, const char *name, ··· 1400 1420 return target; 1401 1421 } 1402 1422 1403 - void object_property_set_bool(Object *obj, const char *name, 1423 + bool object_property_set_bool(Object *obj, const char *name, 1404 1424 bool value, Error **errp) 1405 1425 { 1406 1426 QBool *qbool = qbool_from_bool(value); 1407 - object_property_set_qobject(obj, name, QOBJECT(qbool), errp); 1427 + bool ok = object_property_set_qobject(obj, name, QOBJECT(qbool), errp); 1408 1428 1409 1429 qobject_unref(qbool); 1430 + return ok; 1410 1431 } 1411 1432 1412 1433 bool object_property_get_bool(Object *obj, const char *name, ··· 1431 1452 return retval; 1432 1453 } 1433 1454 1434 - void object_property_set_int(Object *obj, const char *name, 1455 + bool object_property_set_int(Object *obj, const char *name, 1435 1456 int64_t value, Error **errp) 1436 1457 { 1437 1458 QNum *qnum = qnum_from_int(value); 1438 - object_property_set_qobject(obj, name, QOBJECT(qnum), errp); 1459 + bool ok = object_property_set_qobject(obj, name, QOBJECT(qnum), errp); 1439 1460 1440 1461 qobject_unref(qnum); 1462 + return ok; 1441 1463 } 1442 1464 1443 1465 int64_t object_property_get_int(Object *obj, const char *name, ··· 1500 1522 object_property_set_default(prop, QOBJECT(qnum_from_uint(value))); 1501 1523 } 1502 1524 1503 - void object_property_set_uint(Object *obj, const char *name, 1525 + bool object_property_set_uint(Object *obj, const char *name, 1504 1526 uint64_t value, Error **errp) 1505 1527 { 1506 1528 QNum *qnum = qnum_from_uint(value); 1529 + bool ok = object_property_set_qobject(obj, name, QOBJECT(qnum), errp); 1507 1530 1508 - object_property_set_qobject(obj, name, QOBJECT(qnum), errp); 1509 1531 qobject_unref(qnum); 1532 + return ok; 1510 1533 } 1511 1534 1512 1535 uint64_t object_property_get_uint(Object *obj, const char *name, ··· 1567 1590 return ret; 1568 1591 } 1569 1592 1570 - void object_property_parse(Object *obj, const char *name, 1593 + bool object_property_parse(Object *obj, const char *name, 1571 1594 const char *string, Error **errp) 1572 1595 { 1573 1596 Visitor *v = string_input_visitor_new(string); 1574 - object_property_set(obj, name, v, errp); 1597 + bool ok = object_property_set(obj, name, v, errp); 1598 + 1575 1599 visit_free(v); 1600 + return ok; 1576 1601 } 1577 1602 1578 1603 char *object_property_print(Object *obj, const char *name, bool human,
+13 -8
qom/object_interfaces.c
··· 14 14 #include "qapi/opts-visitor.h" 15 15 #include "qemu/config-file.h" 16 16 17 - void user_creatable_complete(UserCreatable *uc, Error **errp) 17 + bool user_creatable_complete(UserCreatable *uc, Error **errp) 18 18 { 19 19 UserCreatableClass *ucc = USER_CREATABLE_GET_CLASS(uc); 20 + Error *err = NULL; 20 21 21 22 if (ucc->complete) { 22 - ucc->complete(uc, errp); 23 + ucc->complete(uc, &err); 24 + error_propagate(errp, err); 23 25 } 26 + return !err; 24 27 } 25 28 26 29 bool user_creatable_can_be_deleted(UserCreatable *uc) ··· 101 104 return obj; 102 105 } 103 106 104 - void user_creatable_add_dict(QDict *qdict, bool keyval, Error **errp) 107 + bool user_creatable_add_dict(QDict *qdict, bool keyval, Error **errp) 105 108 { 106 109 Visitor *v; 107 110 Object *obj; ··· 111 114 type = g_strdup(qdict_get_try_str(qdict, "qom-type")); 112 115 if (!type) { 113 116 error_setg(errp, QERR_MISSING_PARAMETER, "qom-type"); 114 - return; 117 + return false; 115 118 } 116 119 qdict_del(qdict, "qom-type"); 117 120 118 121 id = g_strdup(qdict_get_try_str(qdict, "id")); 119 122 if (!id) { 120 123 error_setg(errp, QERR_MISSING_PARAMETER, "id"); 121 - return; 124 + return false; 122 125 } 123 126 qdict_del(qdict, "id"); 124 127 ··· 130 133 obj = user_creatable_add_type(type, id, qdict, v, errp); 131 134 visit_free(v); 132 135 object_unref(obj); 136 + return !!obj; 133 137 } 134 138 135 139 Object *user_creatable_add_opts(QemuOpts *opts, Error **errp) ··· 260 264 return false; 261 265 } 262 266 263 - void user_creatable_del(const char *id, Error **errp) 267 + bool user_creatable_del(const char *id, Error **errp) 264 268 { 265 269 Object *container; 266 270 Object *obj; ··· 269 273 obj = object_resolve_path_component(container, id); 270 274 if (!obj) { 271 275 error_setg(errp, "object '%s' not found", id); 272 - return; 276 + return false; 273 277 } 274 278 275 279 if (!user_creatable_can_be_deleted(USER_CREATABLE(obj))) { 276 280 error_setg(errp, "object '%s' is in use, can not be deleted", id); 277 - return; 281 + return false; 278 282 } 279 283 280 284 /* ··· 285 289 id)); 286 290 287 291 object_unparent(obj); 292 + return true; 288 293 } 289 294 290 295 void user_creatable_cleanup(void)
+4 -2
qom/qom-qobject.c
··· 17 17 #include "qapi/qobject-input-visitor.h" 18 18 #include "qapi/qobject-output-visitor.h" 19 19 20 - void object_property_set_qobject(Object *obj, 20 + bool object_property_set_qobject(Object *obj, 21 21 const char *name, QObject *value, 22 22 Error **errp) 23 23 { 24 24 Visitor *v; 25 + bool ok; 25 26 26 27 v = qobject_input_visitor_new(value); 27 - object_property_set(obj, name, v, errp); 28 + ok = object_property_set(obj, name, v, errp); 28 29 visit_free(v); 30 + return ok; 29 31 } 30 32 31 33 QObject *object_property_get_qobject(Object *obj, const char *name,