Skip to content

Commit 1768675

Browse files
committed
feat: Adding option to run ZBD remove elements and modify zones
Adding an option to run the ZAC/ZBC depop that also modifies the zones. Signed-off-by: Tyler Erickson <[email protected]>
1 parent d2782dd commit 1768675

File tree

3 files changed

+102
-24
lines changed

3 files changed

+102
-24
lines changed

include/openseachest_util_options.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,15 @@ extern "C"
23272327
REMOVE_PHYSICAL_ELEMENT_LONG_OPT_STRING, required_argument, M_NULLPTR, 0 \
23282328
}
23292329

2330+
#define REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_FLAG \
2331+
removePhysicalElementModifyZones // zero means not set and is not a valid element. Must be non-zero
2332+
#define REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_VAR uint32_t REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_FLAG = UINT32_C(0);
2333+
#define REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_LONG_OPT_STRING "removeElementModifyZones"
2334+
#define REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_LONG_OPT \
2335+
{ \
2336+
REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_LONG_OPT_STRING, required_argument, M_NULLPTR, 0 \
2337+
}
2338+
23302339
#define REPOPULATE_ELEMENTS_FLAG repopulateElements
23312340
#define REPOPULATE_ELEMENTS_VAR getOptBool REPOPULATE_ELEMENTS_FLAG = goFalse;
23322341
#define REPOPULATE_ELEMENTS_LONG_OPT_STRING "repopulateElements"
@@ -4819,6 +4828,8 @@ extern "C"
48194828

48204829
void print_Remove_Physical_Element_Status_Help(bool shortHelp);
48214830

4831+
void print_Remove_Physical_Element_And_Modify_Zones_Help(bool shortHelp);
4832+
48224833
void print_Depop_MaxLBA_Help(bool shortHelp);
48234834

48244835
void print_Repopulate_Elements_Help(bool shortHelp);

src/openseachest_util_options.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3655,6 +3655,27 @@ void print_Remove_Physical_Element_Status_Help(bool shortHelp)
36553655
}
36563656
}
36573657

3658+
void print_Remove_Physical_Element_And_Modify_Zones_Help(bool shortHelp)
3659+
{
3660+
printf("\t--%s [element #] (Zoned Only)\n", REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_LONG_OPT_STRING);
3661+
if (!shortHelp)
3662+
{
3663+
printf("\t\tUse this option to remove a storage element and modify zones\n");
3664+
printf("\t\tfrom use on a Zoned drive (ZBD). When this is done, the\n");
3665+
printf("\t\tdrive will erase all user data and lower the\n");
3666+
printf("\t\tcapacity to a new point where the drive is still\n");
3667+
printf("\t\tusable without the provided element #.\n");
3668+
printf("\t\tUse the --%s option to see the status\n", SHOW_PHYSICAL_ELEMENT_STATUS_LONG_OPT_STRING);
3669+
printf("\t\tof the depopulation operation.\n");
3670+
set_Console_Foreground_Background_Colors(CONSOLE_COLOR_BRIGHT_RED, CONSOLE_COLOR_DEFAULT);
3671+
printf("\t\tThere is an additional risk when performing a remove physical element as it low-level formats\n");
3672+
printf("\t\tthe drive and may make the drive inoperable if it is reset at any time while it is formatting.\n");
3673+
set_Console_Foreground_Background_Colors(CONSOLE_COLOR_DEFAULT, CONSOLE_COLOR_DEFAULT);
3674+
printf("\t\tWARNING: Removing a physical element affect all LUNs/namespaces for devices\n");
3675+
printf("\t\t with multiple logical units or namespaces.\n\n");
3676+
}
3677+
}
3678+
36583679
void print_Depop_MaxLBA_Help(bool shortHelp)
36593680
{
36603681
printf("\t--%s [requested MaxLBA]\n", DEPOP_MAX_LBA_LONG_OPT_STRING);

utils/C/openSeaChest/openSeaChest_Format.c

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// Global Variables //
3838
////////////////////////
3939
const char* util_name = "openSeaChest_Format";
40-
const char* buildVersion = "3.3.2";
40+
const char* buildVersion = "3.4.0";
4141

4242
////////////////////////////
4343
// functions to declare //
@@ -104,6 +104,7 @@ int main(int argc, char* argv[])
104104
SET_SECTOR_SIZE_VARS
105105
SHOW_PHYSICAL_ELEMENT_STATUS_VAR
106106
REMOVE_PHYSICAL_ELEMENT_VAR
107+
REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_VAR
107108
REPOPULATE_ELEMENTS_VAR
108109
DEPOP_MAX_LBA_VAR
109110
NVM_FORMAT_VARS
@@ -164,6 +165,7 @@ int main(int argc, char* argv[])
164165
SHOW_SUPPORTED_FORMATS_LONG_OPT,
165166
SHOW_PHYSICAL_ELEMENT_STATUS_LONG_OPT,
166167
REMOVE_PHYSICAL_ELEMENT_LONG_OPT,
168+
REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_LONG_OPT,
167169
REPOPULATE_ELEMENTS_LONG_OPT,
168170
DEPOP_MAX_LBA_LONG_OPT,
169171
NVM_FORMAT_LONG_OPT,
@@ -350,8 +352,7 @@ int main(int argc, char* argv[])
350352
exit(UTIL_EXIT_ERROR_IN_COMMAND_LINE);
351353
}
352354
}
353-
else if (strcmp(longopts[optionIndex].name, REMOVE_PHYSICAL_ELEMENT_LONG_OPT_STRING) ==
354-
0) // REMOVE_PHYSICAL_ELEMENT_LONG_OPT_STRING
355+
else if (strcmp(longopts[optionIndex].name, REMOVE_PHYSICAL_ELEMENT_LONG_OPT_STRING) == 0)
355356
{
356357
if (!get_And_Validate_Integer_Input_Uint32(C_CAST(const char*, optarg), M_NULLPTR, ALLOW_UNIT_NONE,
357358
&REMOVE_PHYSICAL_ELEMENT_FLAG))
@@ -360,6 +361,15 @@ int main(int argc, char* argv[])
360361
exit(UTIL_EXIT_ERROR_IN_COMMAND_LINE);
361362
}
362363
}
364+
else if (strcmp(longopts[optionIndex].name, REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_LONG_OPT_STRING) == 0)
365+
{
366+
if (!get_And_Validate_Integer_Input_Uint32(C_CAST(const char*, optarg), M_NULLPTR, ALLOW_UNIT_NONE,
367+
&REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_FLAG))
368+
{
369+
print_Error_In_Cmd_Line_Args(REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_LONG_OPT_STRING, optarg);
370+
exit(UTIL_EXIT_ERROR_IN_COMMAND_LINE);
371+
}
372+
}
363373
else if (strcmp(longopts[optionIndex].name, NVM_FORMAT_LONG_OPT_STRING) == 0)
364374
{
365375
NVM_FORMAT_FLAG = true;
@@ -881,7 +891,9 @@ int main(int argc, char* argv[])
881891
// check for other tool specific options here
882892
|| FORMAT_UNIT_FLAG || DISPLAY_LBA_FLAG || (PROGRESS_CHAR != M_NULLPTR) || SHOW_FORMAT_STATUS_LOG_FLAG ||
883893
SET_SECTOR_SIZE_FLAG || SHOW_SUPPORTED_FORMATS_FLAG || SHOW_PHYSICAL_ELEMENT_STATUS_FLAG ||
884-
REMOVE_PHYSICAL_ELEMENT_FLAG > 0 || REPOPULATE_ELEMENTS_FLAG || NVM_FORMAT_FLAG))
894+
REMOVE_PHYSICAL_ELEMENT_FLAG > 0 || REPOPULATE_ELEMENTS_FLAG || NVM_FORMAT_FLAG ||
895+
REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_FLAG > 0
896+
))
885897
{
886898
utility_Usage(true);
887899
free_Handle_List(&HANDLE_LIST, DEVICE_LIST_COUNT);
@@ -935,7 +947,8 @@ int main(int argc, char* argv[])
935947
flags |= HANDLE_RECOMMEND_EXCLUSIVE_ACCESS;
936948
}
937949

938-
if (SET_SECTOR_SIZE_FLAG || FAST_FORMAT_FLAG || REMOVE_PHYSICAL_ELEMENT_FLAG > 0 || REPOPULATE_ELEMENTS_FLAG)
950+
if (SET_SECTOR_SIZE_FLAG || FAST_FORMAT_FLAG || REMOVE_PHYSICAL_ELEMENT_FLAG > 0 ||
951+
REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_FLAG > 0 || REPOPULATE_ELEMENTS_FLAG)
939952
{
940953
flags |= HANDLE_REQUIRE_EXCLUSIVE_ACCESS;
941954
}
@@ -1056,8 +1069,8 @@ int main(int argc, char* argv[])
10561069
}
10571070
free_Handle_List(&HANDLE_LIST, DEVICE_LIST_COUNT);
10581071

1059-
if (SET_SECTOR_SIZE_FLAG || REMOVE_PHYSICAL_ELEMENT_FLAG > 0 || REPOPULATE_ELEMENTS_FLAG ||
1060-
(FORMAT_UNIT_FLAG && FAST_FORMAT_FLAG))
1072+
if (SET_SECTOR_SIZE_FLAG || REMOVE_PHYSICAL_ELEMENT_FLAG > 0 || REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_FLAG > 0 ||
1073+
REPOPULATE_ELEMENTS_FLAG || (FORMAT_UNIT_FLAG && FAST_FORMAT_FLAG))
10611074
{
10621075
// These options all do a low-level format that has a risk of leaving the drive inoperable if it is interrupted.
10631076
// Warn the user one last time and provide 30 seconds to cancel the operation
@@ -1403,16 +1416,19 @@ int main(int argc, char* argv[])
14031416
ptrPhysicalElement elementList = M_REINTERPRET_CAST(
14041417
ptrPhysicalElement, safe_malloc(numberOfDescriptors * sizeof(physicalElement)));
14051418
uint32_t depopElementID = UINT32_C(0);
1406-
uint16_t maxDepop = UINT16_C(0);
1407-
uint16_t currentDepop = UINT16_C(0);
1419+
uint16_t maxDepop = UINT16_C(0);
1420+
uint16_t currentDepop = UINT16_C(0);
14081421
if (elementList)
14091422
{
14101423
safe_memset(elementList, numberOfDescriptors * sizeof(physicalElement), 0,
14111424
numberOfDescriptors * sizeof(physicalElement));
1412-
if (SUCCESS ==
1413-
get_Physical_Element_Descriptors_2(&deviceList[deviceIter], numberOfDescriptors, &depopElementID, &maxDepop, &currentDepop, elementList))
1425+
if (SUCCESS == get_Physical_Element_Descriptors_2(&deviceList[deviceIter], numberOfDescriptors,
1426+
&depopElementID, &maxDepop, &currentDepop,
1427+
elementList))
14141428
{
1415-
show_Physical_Element_Descriptors_2(numberOfDescriptors, elementList, depopTime, depopElementID, maxDepop, currentDepop);
1429+
printf("Depop time (Dec/Hex): %" PRIu64 "/%" PRIX64 "h\n", depopTime, depopTime);
1430+
show_Physical_Element_Descriptors_2(numberOfDescriptors, elementList, depopTime,
1431+
depopElementID, maxDepop, currentDepop);
14161432
}
14171433
else
14181434
{
@@ -1733,32 +1749,60 @@ int main(int argc, char* argv[])
17331749
}
17341750
}
17351751

1736-
if (REMOVE_PHYSICAL_ELEMENT_FLAG > 0)
1752+
if (REMOVE_PHYSICAL_ELEMENT_FLAG > 0 || REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_FLAG > 0)
17371753
{
17381754
if (LOW_LEVEL_FORMAT_FLAG)
17391755
{
17401756
bool depopSupport = is_Depopulation_Feature_Supported(&deviceList[deviceIter], M_NULLPTR);
17411757
if (depopSupport)
17421758
{
1743-
switch (perform_Depopulate_Physical_Element(&deviceList[deviceIter], REMOVE_PHYSICAL_ELEMENT_FLAG,
1744-
DEPOP_MAX_LBA_FLAG, POLL_FLAG))
1759+
bool modifyZones = false;
1760+
uint32_t elementID = REMOVE_PHYSICAL_ELEMENT_FLAG;
1761+
if (REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_FLAG > 0)
1762+
{
1763+
elementID = REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_FLAG;
1764+
modifyZones = true;
1765+
}
1766+
switch (perform_Depopulate_Physical_Element2(&deviceList[deviceIter], elementID, DEPOP_MAX_LBA_FLAG,
1767+
POLL_FLAG, modifyZones))
17451768
{
17461769
case SUCCESS:
17471770
if (VERBOSITY_QUIET < toolVerbosity)
17481771
{
17491772
if (POLL_FLAG)
17501773
{
1751-
printf("Successfully depopulated physical element %" PRIu32 "!\n",
1752-
REMOVE_PHYSICAL_ELEMENT_FLAG);
1774+
if (modifyZones)
1775+
{
1776+
printf("Successfully depopulated physical element %" PRIu32
1777+
" and modified zones!\n",
1778+
elementID);
1779+
}
1780+
else
1781+
{
1782+
printf("Successfully depopulated physical element %" PRIu32 "!\n", elementID);
1783+
}
17531784
}
17541785
else
17551786
{
1756-
printf("Successfully started depopulation for physical element %" PRIu32 "!\n",
1757-
REMOVE_PHYSICAL_ELEMENT_FLAG);
1758-
printf("The device may take a long time before it is ready to accept all commands "
1759-
"again.\n");
1760-
printf("Use \"--%s depop\" or \"--%s\" to check progress.\n", PROGRESS_LONG_OPT_STRING,
1761-
SHOW_PHYSICAL_ELEMENT_STATUS_LONG_OPT_STRING);
1787+
if (modifyZones)
1788+
{
1789+
printf("Successfully started depopulation for physical element %" PRIu32
1790+
" and modifying zones!\n",
1791+
elementID);
1792+
printf("The device may take a long time before it is ready to accept all commands "
1793+
"again.\n");
1794+
printf("Use \"--%s depop\" or \"--%s\" to check progress.\n",
1795+
PROGRESS_LONG_OPT_STRING, SHOW_PHYSICAL_ELEMENT_STATUS_LONG_OPT_STRING);
1796+
}
1797+
else
1798+
{
1799+
printf("Successfully started depopulation for physical element %" PRIu32 "!\n",
1800+
elementID);
1801+
printf("The device may take a long time before it is ready to accept all commands "
1802+
"again.\n");
1803+
printf("Use \"--%s depop\" or \"--%s\" to check progress.\n",
1804+
PROGRESS_LONG_OPT_STRING, SHOW_PHYSICAL_ELEMENT_STATUS_LONG_OPT_STRING);
1805+
}
17621806
}
17631807
if (deviceList[deviceIter].drive_info.numberOfLUs > 1)
17641808
{
@@ -1784,7 +1828,7 @@ int main(int argc, char* argv[])
17841828
default:
17851829
if (VERBOSITY_QUIET < toolVerbosity)
17861830
{
1787-
printf("Failed to depopulate element %" PRIu32 ".\n", REMOVE_PHYSICAL_ELEMENT_FLAG);
1831+
printf("Failed to depopulate element %" PRIu32 ".\n", elementID);
17881832
}
17891833
exitCode = UTIL_EXIT_OPERATION_FAILURE;
17901834
break;
@@ -2145,6 +2189,7 @@ void utility_Usage(bool shortUsage)
21452189
printf("\t%s -d %s --%s\n", util_name, deviceHandleExample, LOWLEVEL_INFO_LONG_OPT_STRING);
21462190
printf("\t%s -d %s --%s\n", util_name, deviceHandleExample, SHOW_PHYSICAL_ELEMENT_STATUS_LONG_OPT_STRING);
21472191
printf("\t%s -d %s --%s 2\n", util_name, deviceHandleExample, REMOVE_PHYSICAL_ELEMENT_LONG_OPT_STRING);
2192+
printf("\t%s -d %s --%s 2\n", util_name, deviceHandleExample, REMOVE_PHYSICAL_ELEMENT_MOD_ZONES_LONG_OPT_STRING);
21482193
printf("\t%s -d %s --%s\n", util_name, deviceHandleExample, REPOPULATE_ELEMENTS_LONG_OPT_STRING);
21492194
printf("\t%s -d %s --%s\n", util_name, deviceHandleExample, SHOW_SUPPORTED_FORMATS_LONG_OPT_STRING);
21502195
printf("\t%s -d %s --%s\n", util_name, deviceHandleExample, SHOW_FORMAT_STATUS_LOG_LONG_OPT_STRING);
@@ -2233,6 +2278,7 @@ void utility_Usage(bool shortUsage)
22332278
// utility data destructive tests/operations go here
22342279
print_Pattern_Help(shortUsage);
22352280
print_Remove_Physical_Element_Status_Help(shortUsage);
2281+
print_Remove_Physical_Element_And_Modify_Zones_Help(shortUsage);
22362282
print_Repopulate_Elements_Help(shortUsage);
22372283
print_Set_Sector_Size_Help(shortUsage);
22382284
printf("\n\tSAS Only:\n\t=========\n");

0 commit comments

Comments
 (0)