Changeset fc265b4 in mainline
- Timestamp:
- 2025-05-07T10:41:29Z (5 weeks ago)
- Children:
- af4ecb76
- Parents:
- ac4b70b
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/hrctl/hrctl.c
rac4b70b rfc265b4 229 229 } 230 230 231 static int handle_create( int argc, char **argv)231 static int handle_create(hr_t *hr, int argc, char **argv) 232 232 { 233 233 if (optind >= argc) { … … 287 287 } 288 288 289 hr_t *hr; 290 errno_t rc = hr_sess_init(&hr); 291 if (rc != EOK) { 292 printf(NAME ": server session init failed: %s\n", 293 str_error(rc)); 294 goto error; 295 } 296 297 rc = hr_create(hr, vol_config); 289 errno_t rc = hr_create(hr, vol_config); 298 290 if (rc != EOK) { 299 291 printf(NAME ": creation failed: %s\n", … … 301 293 goto error; 302 294 } 303 304 hr_sess_destroy(hr);305 295 306 296 free(vol_config); … … 311 301 } 312 302 313 static int handle_assemble( int argc, char **argv)303 static int handle_assemble(hr_t *hr, int argc, char **argv) 314 304 { 315 305 if (optind >= argc) { 316 306 size_t cnt; 317 errno_t rc = hr_auto_assemble( &cnt);307 errno_t rc = hr_auto_assemble(hr, &cnt); 318 308 if (rc != EOK) { 319 309 /* XXX: here have own error codes */ … … 353 343 } 354 344 355 hr_t *hr;356 errno_t rc = hr_sess_init(&hr);357 if (rc != EOK) {358 printf(NAME ": server session init failed: %s\n",359 str_error(rc));360 goto error;361 }362 363 345 size_t cnt; 364 rc = hr_assemble(hr, vol_config, &cnt);346 errno_t rc = hr_assemble(hr, vol_config, &cnt); 365 347 if (rc != EOK) { 366 348 printf(NAME ": assmeble failed: %s\n", str_error(rc)); … … 369 351 370 352 printf("hrctl: auto assembled %zu volumes\n", cnt); 371 372 hr_sess_destroy(hr);373 353 374 354 free(vol_config); … … 379 359 } 380 360 381 static int handle_disassemble( int argc, char **argv)361 static int handle_disassemble(hr_t *hr, int argc, char **argv) 382 362 { 383 363 if (optind >= argc) { 384 errno_t rc = hr_stop_all( );364 errno_t rc = hr_stop_all(hr); 385 365 if (rc != EOK) { 386 366 printf(NAME ": stopping some volumes failed: %s\n", … … 398 378 const char *devname = argv[optind++]; 399 379 400 errno_t rc = hr_stop( devname);380 errno_t rc = hr_stop(hr, devname); 401 381 if (rc != EOK) { 402 382 printf(NAME ": disassembly of device \"%s\" failed: %s\n", … … 408 388 } 409 389 410 static int handle_modify( int argc, char **argv)390 static int handle_modify(hr_t *hr, int argc, char **argv) 411 391 { 412 392 if (optind >= argc) { … … 432 412 optind++; 433 413 unsigned long extent = strtol(argv[optind++], NULL, 10); 434 errno_t rc = hr_fail_extent( volname, extent);414 errno_t rc = hr_fail_extent(hr, volname, extent); 435 415 if (rc != EOK) { 436 416 printf(NAME ": failing extent failed: %s\n", … … 441 421 str_cmp(argv[optind], "-h") == 0) { 442 422 optind++; 443 errno_t rc = hr_add_hotspare( volname, argv[optind++]);423 errno_t rc = hr_add_hotspare(hr, volname, argv[optind++]); 444 424 if (rc != EOK) { 445 425 printf(NAME ": adding hotspare failed: %s\n", … … 455 435 } 456 436 457 static int handle_status( int argc, char **argv)437 static int handle_status(hr_t *hr, int argc, char **argv) 458 438 { 459 439 (void)argc; 460 440 (void)argv; 461 441 462 errno_t rc = hr_print_status( );442 errno_t rc = hr_print_status(hr); 463 443 if (rc != EOK) { 464 444 printf(NAME ": status printing failed: %s\n", str_error(rc)); … … 472 452 { 473 453 int rc = EXIT_SUCCESS; 474 int c;454 hr_t *hr = NULL; 475 455 476 456 if (argc < 2) { … … 479 459 } 480 460 481 c = 0; 461 if (hr_sess_init(&hr) != EOK) { 462 printf(NAME ": hr server session init failed: %s\n", 463 str_error(rc)); 464 return EXIT_FAILURE; 465 } 466 482 467 optreset = 1; 483 468 optind = 0; … … 493 478 }; 494 479 495 while (c != -1) { 496 c = getopt_long(argc, argv, "hcadms", top_level_opts, NULL); 497 switch (c) { 498 case 'h': 499 usage(); 500 return EXIT_SUCCESS; 501 case 'c': 502 rc = handle_create(argc, argv); 503 goto end; 504 case 'a': 505 rc = handle_assemble(argc, argv); 506 goto end; 507 case 'd': 508 rc = handle_disassemble(argc, argv); 509 goto end; 510 case 'm': 511 rc = handle_modify(argc, argv); 512 goto end; 513 case 's': 514 rc = handle_status(argc, argv); 515 goto end; 516 default: 517 goto end; 518 } 480 int c = getopt_long(argc, argv, "hcadms", top_level_opts, NULL); 481 switch (c) { 482 case 'h': 483 usage(); 484 goto end; 485 case 'c': 486 rc = handle_create(hr, argc, argv); 487 goto end; 488 case 'a': 489 rc = handle_assemble(hr, argc, argv); 490 goto end; 491 case 'd': 492 rc = handle_disassemble(hr, argc, argv); 493 goto end; 494 case 'm': 495 rc = handle_modify(hr, argc, argv); 496 goto end; 497 case 's': 498 rc = handle_status(hr, argc, argv); 499 goto end; 500 default: 501 goto end; 519 502 } 520 503 521 504 end: 505 hr_sess_destroy(hr); 506 522 507 if (rc != EXIT_SUCCESS) 523 508 printf(NAME ": use --help to see usage\n"); -
uspace/lib/device/include/hr.h
rac4b70b rfc265b4 124 124 extern errno_t hr_create(hr_t *, hr_config_t *); 125 125 extern errno_t hr_assemble(hr_t *, hr_config_t *, size_t *); 126 extern errno_t hr_auto_assemble( size_t *);127 extern errno_t hr_stop( const char *);128 extern errno_t hr_stop_all( void);129 extern errno_t hr_fail_extent( const char *, unsigned long);130 extern errno_t hr_add_hotspare( const char *, const char *);131 extern errno_t hr_print_status( void);126 extern errno_t hr_auto_assemble(hr_t *, size_t *); 127 extern errno_t hr_stop(hr_t *, const char *); 128 extern errno_t hr_stop_all(hr_t *); 129 extern errno_t hr_fail_extent(hr_t *, const char *, unsigned long); 130 extern errno_t hr_add_hotspare(hr_t *, const char *, const char *); 131 extern errno_t hr_print_status(hr_t *); 132 132 extern const char *hr_get_vol_status_msg(hr_vol_status_t); 133 133 extern const char *hr_get_ext_status_msg(hr_ext_status_t); -
uspace/lib/device/src/hr.c
rac4b70b rfc265b4 148 148 } 149 149 150 errno_t hr_auto_assemble(size_t *rassembled_cnt) 151 { 152 hr_t *hr; 150 errno_t hr_auto_assemble(hr_t *hr, size_t *rassembled_cnt) 151 { 153 152 errno_t rc; 154 153 size_t assembled_cnt; 155 156 rc = hr_sess_init(&hr);157 if (rc != EOK)158 return rc;159 154 160 155 async_exch_t *exch = async_exchange_begin(hr->sess); … … 179 174 *rassembled_cnt = assembled_cnt; 180 175 error: 181 hr_sess_destroy(hr);182 176 return rc; 183 177 } … … 266 260 } 267 261 268 errno_t hr_stop(const char *devname) 269 { 270 hr_t *hr; 262 errno_t hr_stop(hr_t *hr, const char *devname) 263 { 271 264 errno_t rc; 272 265 async_exch_t *exch; … … 277 270 return rc; 278 271 279 rc = hr_sess_init(&hr);280 if (rc != EOK)281 return rc;282 283 272 exch = async_exchange_begin(hr->sess); 284 273 if (exch == NULL) { … … 290 279 async_exchange_end(exch); 291 280 error: 292 hr_sess_destroy(hr); 293 return rc; 294 } 295 296 errno_t hr_stop_all(void) 297 { 298 hr_t *hr; 299 async_exch_t *exch; 300 errno_t rc; 301 302 rc = hr_sess_init(&hr); 303 if (rc != EOK) 304 return rc; 281 return rc; 282 } 283 284 errno_t hr_stop_all(hr_t *hr) 285 { 286 async_exch_t *exch; 287 errno_t rc; 305 288 306 289 exch = async_exchange_begin(hr->sess); … … 313 296 async_exchange_end(exch); 314 297 error: 315 hr_sess_destroy(hr); 316 return rc; 317 } 318 319 errno_t hr_fail_extent(const char *volume_name, unsigned long extent) 320 { 321 hr_t *hr; 298 return rc; 299 } 300 301 errno_t hr_fail_extent(hr_t *hr, const char *volume_name, unsigned long extent) 302 { 322 303 errno_t rc; 323 304 async_exch_t *exch; … … 328 309 return rc; 329 310 330 rc = hr_sess_init(&hr);331 if (rc != EOK)332 return rc;333 334 311 exch = async_exchange_begin(hr->sess); 335 312 if (exch == NULL) { … … 341 318 async_exchange_end(exch); 342 319 error: 343 hr_sess_destroy(hr); 344 return rc; 345 } 346 347 errno_t hr_add_hotspare(const char *volume_name, const char *hotspare) 348 { 349 hr_t *hr; 320 return rc; 321 } 322 323 errno_t hr_add_hotspare(hr_t *hr, const char *volume_name, const char *hotspare) 324 { 350 325 errno_t rc; 351 326 async_exch_t *exch; … … 360 335 return rc; 361 336 362 rc = hr_sess_init(&hr);363 if (rc != EOK)364 return rc;365 366 337 exch = async_exchange_begin(hr->sess); 367 338 if (exch == NULL) { … … 373 344 async_exchange_end(exch); 374 345 error: 375 hr_sess_destroy(hr); 376 return rc; 377 } 378 379 errno_t hr_print_status(void) 380 { 381 hr_t *hr; 346 return rc; 347 } 348 349 errno_t hr_print_status(hr_t *hr) 350 { 382 351 errno_t rc, retval; 383 352 async_exch_t *exch; … … 385 354 size_t size, i; 386 355 hr_vol_info_t *vols = NULL; 387 388 rc = hr_sess_init(&hr);389 if (rc != EOK)390 return rc;391 356 392 357 exch = async_exchange_begin(hr->sess); … … 429 394 430 395 if (size == 0) { 431 printf("no active arrays\n");396 printf("no active volumes\n"); 432 397 goto error; 433 398 } … … 440 405 441 406 error: 442 hr_sess_destroy(hr);443 407 if (vols != NULL) 444 408 free(vols);
Note:
See TracChangeset
for help on using the changeset viewer.