Changeset 372df8f in mainline for uspace/srv/bd/vbd/disk.c
- Timestamp:
- 2015-10-09T07:00:23Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0ecfc62
- Parents:
- 0bde8523
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/vbd/disk.c
r0bde8523 r372df8f 48 48 #include "types/vbd.h" 49 49 50 static fibril_mutex_t vbds_disks_lock; 50 51 static list_t vbds_disks; /* of vbds_disk_t */ 51 52 static list_t vbds_parts; /* of vbds_part_t */ 53 54 static category_id_t part_cid; 52 55 53 56 static int vbds_bd_open(bd_srvs_t *, bd_srv_t *); … … 83 86 } 84 87 85 void vbds_disks_init(void) 86 { 88 int vbds_disks_init(void) 89 { 90 int rc; 91 92 fibril_mutex_initialize(&vbds_disks_lock); 87 93 list_initialize(&vbds_disks); 88 94 list_initialize(&vbds_parts); 89 } 95 96 rc = loc_category_get_id("partition", &part_cid, 0); 97 if (rc != EOK) { 98 log_msg(LOG_DEFAULT, LVL_ERROR, "Error looking up partition " 99 "category."); 100 return EIO; 101 } 102 103 return EOK; 104 } 105 106 /** Check for new disk devices */ 107 static int vbds_disks_check_new(void) 108 { 109 bool already_known; 110 category_id_t disk_cat; 111 service_id_t *svcs; 112 size_t count, i; 113 int rc; 114 115 fibril_mutex_lock(&vbds_disks_lock); 116 117 rc = loc_category_get_id("disk", &disk_cat, IPC_FLAG_BLOCKING); 118 if (rc != EOK) { 119 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed resolving category 'disk'."); 120 fibril_mutex_unlock(&vbds_disks_lock); 121 return ENOENT; 122 } 123 124 rc = loc_category_get_svcs(disk_cat, &svcs, &count); 125 if (rc != EOK) { 126 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed getting list of disk " 127 "devices."); 128 fibril_mutex_unlock(&vbds_disks_lock); 129 return EIO; 130 } 131 132 for (i = 0; i < count; i++) { 133 already_known = false; 134 135 list_foreach(vbds_disks, ldisks, vbds_disk_t, disk) { 136 if (disk->svc_id == svcs[i]) { 137 already_known = true; 138 break; 139 } 140 } 141 142 if (!already_known) { 143 log_msg(LOG_DEFAULT, LVL_NOTE, "Found disk '%lu'", 144 (unsigned long) svcs[i]); 145 rc = vbds_disk_add(svcs[i]); 146 if (rc != EOK) { 147 log_msg(LOG_DEFAULT, LVL_ERROR, "Could not add " 148 "disk."); 149 } 150 } 151 } 152 153 fibril_mutex_unlock(&vbds_disks_lock); 154 return EOK; 155 } 156 90 157 91 158 static int vbds_disk_by_svcid(service_id_t sid, vbds_disk_t **rdisk) … … 210 277 } 211 278 279 static void vbds_disk_cat_change_cb(void) 280 { 281 (void) vbds_disks_check_new(); 282 } 283 284 int vbds_disk_discovery_start(void) 285 { 286 int rc; 287 288 rc = loc_register_cat_change_cb(vbds_disk_cat_change_cb); 289 if (rc != EOK) { 290 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering callback " 291 "for disk discovery (%d).", rc); 292 return rc; 293 } 294 295 return vbds_disks_check_new(); 296 } 297 212 298 int vbds_disk_add(service_id_t sid) 213 299 { … … 277 363 rc = vbds_part_add(disk, part, NULL); 278 364 if (rc != EOK) { 279 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding partitio "365 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding partition " 280 366 "(disk %s)", disk->svc_name); 281 367 } … … 313 399 block_fini(sid); 314 400 free(disk); 401 return EOK; 402 } 403 404 /** Get list of disks as array of service IDs. */ 405 int vbds_disk_get_ids(service_id_t *id_buf, size_t buf_size, size_t *act_size) 406 { 407 size_t act_cnt; 408 size_t buf_cnt; 409 410 fibril_mutex_lock(&vbds_disks_lock); 411 412 buf_cnt = buf_size / sizeof(service_id_t); 413 414 act_cnt = list_count(&vbds_disks); 415 *act_size = act_cnt * sizeof(service_id_t); 416 417 if (buf_size % sizeof(service_id_t) != 0) { 418 fibril_mutex_unlock(&vbds_disks_lock); 419 return EINVAL; 420 } 421 422 size_t pos = 0; 423 list_foreach(vbds_disks, ldisks, vbds_disk_t, disk) { 424 if (pos < buf_cnt) 425 id_buf[pos] = disk->svc_id; 426 pos++; 427 } 428 429 fibril_mutex_unlock(&vbds_disks_lock); 315 430 return EOK; 316 431 } … … 751 866 if (rc != EOK) { 752 867 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering " 753 "service %s .", name);868 "service %s (%d).", name, rc); 754 869 free(name); 755 870 free(part); 871 return EIO; 872 } 873 874 rc = loc_service_add_to_cat(psid, part_cid); 875 if (rc != EOK) { 876 log_msg(LOG_DEFAULT, LVL_ERROR, "Failled adding partition " 877 "service %s to partition category.", name); 878 free(name); 879 free(part); 880 881 rc = loc_service_unregister(psid); 882 if (rc != EOK) { 883 log_msg(LOG_DEFAULT, LVL_ERROR, "Error unregistering " 884 "service. Rollback failed."); 885 } 756 886 return EIO; 757 887 }
Note:
See TracChangeset
for help on using the changeset viewer.