Skip to content

Commit e02de72

Browse files
committed
govc: add disk.ls '-a' flag
Deleting an FCD file backing can create an orphan FCD. An orphaned ID is returned by the ListVStorageObject API, but calling RetrieveVStorageObject with an orphan ID results in a NotFound fault. The disk.ls command would return an error and suggest: use 'disk.ls -R' to reconcile datastore inventory The -R flag calls ReconcileDatastoreInventory, which normally cleans up such orphans, but we have seen cases where it does not. This change ignores orphans by default. The new '-a' flag will list *all* orphans (if any) and includes the disk.ls -R suggestion. Fixes #3639 Signed-off-by: Doug MacEachern <[email protected]>
1 parent 46d5d87 commit e02de72

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

cli/disk/ls.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
type ls struct {
3737
*flags.DatastoreFlag
38+
all bool
3839
long bool
3940
path bool
4041
r bool
@@ -51,6 +52,7 @@ func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
5152
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
5253
cmd.DatastoreFlag.Register(ctx, f)
5354

55+
f.BoolVar(&cmd.all, "a", false, "List IDs with missing file backing")
5456
f.BoolVar(&cmd.long, "l", false, "Long listing format")
5557
f.BoolVar(&cmd.path, "L", false, "Print disk backing path instead of disk name")
5658
f.BoolVar(&cmd.r, "R", false, "Reconcile the datastore inventory info")
@@ -167,7 +169,18 @@ func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
167169
if err != nil {
168170
if filterNotFound && fault.Is(err, &types.NotFound{}) {
169171
// The case when an FCD is deleted by something other than DeleteVStorageObject_Task, such as VM destroy
170-
return fmt.Errorf("%s not found: use 'disk.ls -R' to reconcile datastore inventory", id)
172+
if cmd.all {
173+
obj := VStorageObject{VStorageObject: types.VStorageObject{
174+
Config: types.VStorageObjectConfigInfo{
175+
BaseConfigInfo: types.BaseConfigInfo{
176+
Id: types.ID{Id: id},
177+
Name: "not found: use 'disk.ls -R' to reconcile datastore inventory",
178+
},
179+
},
180+
}}
181+
res.Objects = append(res.Objects, obj)
182+
}
183+
continue
171184
}
172185
return fmt.Errorf("retrieve %q: %s", id, err)
173186
}

govc/USAGE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,7 @@ Options:
21502150
-L=false Print disk backing path instead of disk name
21512151
-R=false Reconcile the datastore inventory info
21522152
-T=false List attached tags
2153+
-a=false List IDs with missing file backing
21532154
-c= Query tag category
21542155
-ds= Datastore [GOVC_DATASTORE]
21552156
-l=false Long listing format

govc/test/disk.bats

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,24 @@ load test_helper
204204

205205
run govc disk.ls
206206
assert_success
207+
[ ${#lines[@]} -eq 2 ]
207208

208209
path=$(govc disk.ls -json "$id" | jq -r .objects[].config.backing.filePath)
209210
run govc datastore.rm "$path"
210211
assert_success
211212

213+
# file backing was removed without using disk.rm, results in NotFound fault
214+
run govc disk.ls "$id"
215+
assert_failure
216+
212217
run govc disk.ls
213-
assert_failure # file backing was removed without using disk.rm, results in NotFound fault
218+
assert_success
219+
[ ${#lines[@]} -eq 1 ]
220+
221+
run govc disk.ls -a
222+
assert_success
223+
[ ${#lines[@]} -eq 2 ]
224+
assert_matches "not found"
214225

215226
run govc disk.ls -R
216227
assert_success

0 commit comments

Comments
 (0)