multitape_nuke.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "platform.h"
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. #include "storage.h"
  6. #include "multitape.h"
  7. /**
  8. * nuketape(machinenum, storage_modified):
  9. * Delete all files in the archive set. If the data on the server has been
  10. * modified, set ${*storage_modified} to 1.
  11. */
  12. int
  13. nuketape(uint64_t machinenum, int * storage_modified)
  14. {
  15. STORAGE_D * SD;
  16. uint8_t seqnum[32];
  17. uint8_t * flist;
  18. size_t nfiles;
  19. size_t i;
  20. /* Start a storage-layer fsck transaction. */
  21. if ((SD = storage_fsck_start(machinenum, seqnum, 0, 1)) == NULL)
  22. goto err0;
  23. /* Obtain a list of metadata files. */
  24. if (storage_directory_read(machinenum, 'm', 1, &flist, &nfiles))
  25. goto err1;
  26. /* Iterate through the metadata files, deleting them. */
  27. for (i = 0; i < nfiles; i++) {
  28. if (storage_delete_file(SD, 'm', &flist[i * 32]))
  29. goto err2;
  30. }
  31. /* Free list of metadata files. */
  32. free(flist);
  33. /* Obtain a list of metaindex fragments. */
  34. if (storage_directory_read(machinenum, 'i', 1, &flist, &nfiles))
  35. goto err1;
  36. /* Iterate through the metaindex fragments, deleting them. */
  37. for (i = 0; i < nfiles; i++) {
  38. if (storage_delete_file(SD, 'i', &flist[i * 32]))
  39. goto err2;
  40. }
  41. /* Free list of metaindex fragments. */
  42. free(flist);
  43. /* Obtain a list of chunk files. */
  44. if (storage_directory_read(machinenum, 'c', 1, &flist, &nfiles))
  45. goto err1;
  46. /* Iterate through the chunk files, deleting them. */
  47. for (i = 0; i < nfiles; i++) {
  48. if (storage_delete_file(SD, 'c', &flist[i * 32]))
  49. goto err2;
  50. }
  51. /* Free list of chunk files. */
  52. free(flist);
  53. /* Finish the storage layer fsck transaction. */
  54. if (storage_delete_end(SD))
  55. goto err0;
  56. /*
  57. * Bypass the normal multitape transaction commit code (which makes
  58. * sure that the cache directory is in sync with the server) and
  59. * ask the storage layer to commit the transaction.
  60. */
  61. if (storage_transaction_commit(machinenum, seqnum, 1, storage_modified))
  62. goto err0;
  63. /* Success! */
  64. return (0);
  65. err2:
  66. free(flist);
  67. err1:
  68. storage_delete_free(SD);
  69. err0:
  70. /* Failure! */
  71. return (-1);
  72. }