Skip to content

Commit efd3a91

Browse files
authored
Merge pull request #454 from codenrhoden/bugfix/ceph_parse_watchers
Handle varying output formats for rbd status
2 parents 0c1beda + 544afc0 commit efd3a91

File tree

3 files changed

+148
-54
lines changed

3 files changed

+148
-54
lines changed

drivers/storage/rbd/executor/rbd_executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (d *driver) LocalDevices(
7676
ctx types.Context,
7777
opts *types.LocalDevicesOpts) (*types.LocalDevices, error) {
7878

79-
devMap, err := utils.GetMappedRBDs()
79+
devMap, err := utils.GetMappedRBDs(ctx)
8080
if err != nil {
8181
return nil, err
8282
}

drivers/storage/rbd/storage/rbd_storage.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ package storage
55
import (
66
"regexp"
77

8-
log "github.com/Sirupsen/logrus"
9-
108
gofig "github.com/akutz/gofig/types"
119
"github.com/akutz/goof"
1210

@@ -45,9 +43,9 @@ func (d *driver) Name() string {
4543
}
4644

4745
// Init initializes the driver.
48-
func (d *driver) Init(context types.Context, config gofig.Config) error {
46+
func (d *driver) Init(ctx types.Context, config gofig.Config) error {
4947
d.config = config
50-
log.Info("storage driver initialized")
48+
ctx.Info("storage driver initialized")
5149
return nil
5250
}
5351

@@ -75,15 +73,15 @@ func (d *driver) Volumes(
7573
opts *types.VolumesOpts) ([]*types.Volume, error) {
7674

7775
// Get all Volumes in all pools
78-
pools, err := utils.GetRadosPools()
76+
pools, err := utils.GetRadosPools(ctx)
7977
if err != nil {
8078
return nil, err
8179
}
8280

8381
var volumes []*types.Volume
8482

8583
for _, pool := range pools {
86-
images, err := utils.GetRBDImages(pool)
84+
images, err := utils.GetRBDImages(ctx, pool)
8785
if err != nil {
8886
return nil, err
8987
}
@@ -110,7 +108,7 @@ func (d *driver) VolumeInspect(
110108
return nil, err
111109
}
112110

113-
info, err := utils.GetRBDInfo(pool, image)
111+
info, err := utils.GetRBDInfo(ctx, pool, image)
114112
if err != nil {
115113
return nil, err
116114
}
@@ -149,14 +147,14 @@ func (d *driver) VolumeCreate(ctx types.Context, volumeName string,
149147
"opts.size": *opts.Size,
150148
}
151149

152-
log.WithFields(fields).Debug("creating volume")
150+
ctx.WithFields(fields).Debug("creating volume")
153151

154152
pool, imageName, err := d.parseVolumeID(&volumeName)
155153
if err != nil {
156154
return nil, err
157155
}
158156

159-
info, err := utils.GetRBDInfo(pool, imageName)
157+
info, err := utils.GetRBDInfo(ctx, pool, imageName)
160158
if err != nil {
161159
return nil, err
162160
}
@@ -171,6 +169,7 @@ func (d *driver) VolumeCreate(ctx types.Context, volumeName string,
171169
features := []*string{&featureLayering}
172170

173171
err = utils.RBDCreate(
172+
ctx,
174173
pool,
175174
imageName,
176175
opts.Size,
@@ -220,18 +219,18 @@ func (d *driver) VolumeRemove(
220219
"volumeID": volumeID,
221220
}
222221

223-
log.WithFields(fields).Debug("deleting volume")
222+
ctx.WithFields(fields).Debug("deleting volume")
224223

225224
pool, imageName, err := d.parseVolumeID(&volumeID)
226225
if err != nil {
227226
return goof.WithError("Unable to set image name", err)
228227
}
229228

230-
err = utils.RBDRemove(pool, imageName)
229+
err = utils.RBDRemove(ctx, pool, imageName)
231230
if err != nil {
232231
return goof.WithError("Error while deleting RBD image", err)
233232
}
234-
log.WithFields(fields).Debug("removed volume")
233+
ctx.WithFields(fields).Debug("removed volume")
235234

236235
return nil
237236
}
@@ -246,7 +245,7 @@ func (d *driver) VolumeAttach(
246245
"volumeID": volumeID,
247246
}
248247

249-
log.WithFields(fields).Debug("attaching volume")
248+
ctx.WithFields(fields).Debug("attaching volume")
250249

251250
pool, imageName, err := d.parseVolumeID(&volumeID)
252251
if err != nil {
@@ -268,7 +267,7 @@ func (d *driver) VolumeAttach(
268267
}
269268
}
270269

271-
_, err = utils.RBDMap(pool, imageName)
270+
_, err = utils.RBDMap(ctx, pool, imageName)
272271
if err != nil {
273272
return nil, "", err
274273
}
@@ -295,10 +294,10 @@ func (d *driver) VolumeDetach(
295294
"volumeID": volumeID,
296295
}
297296

298-
log.WithFields(fields).Debug("detaching volume")
297+
ctx.WithFields(fields).Debug("detaching volume")
299298

300299
// Can't rely on local devices header, so get local attachments
301-
localAttachMap, err := utils.GetMappedRBDs()
300+
localAttachMap, err := utils.GetMappedRBDs(ctx)
302301
if err != nil {
303302
return nil, err
304303
}
@@ -308,7 +307,7 @@ func (d *driver) VolumeDetach(
308307
return nil, goof.New("Volume not attached")
309308
}
310309

311-
err = utils.RBDUnmap(&dev)
310+
err = utils.RBDUnmap(ctx, &dev)
312311
if err != nil {
313312
return nil, goof.WithError("Unable to detach volume", err)
314313
}
@@ -371,7 +370,7 @@ func (d *driver) toTypeVolumes(
371370
// rely on that being present unless getAttachments.Devices is set
372371
if getAttachments.Requested() {
373372
var err error
374-
localAttachMap, err = utils.GetMappedRBDs()
373+
localAttachMap, err = utils.GetMappedRBDs(ctx)
375374
if err != nil {
376375
return nil, err
377376
}
@@ -403,7 +402,7 @@ func (d *driver) toTypeVolumes(
403402
if ok {
404403
attachment.DeviceName = ld.DeviceMap[*rbdID]
405404
} else {
406-
log.Warnf("Unable to get local device map for volume %s", *rbdID)
405+
ctx.Warnf("Unable to get local device map for volume %s", *rbdID)
407406
}
408407
}
409408
attachments = append(attachments, attachment)
@@ -412,9 +411,11 @@ func (d *driver) toTypeVolumes(
412411
//Check if RBD has watchers to infer attachment
413412
//to a different host
414413
b, err := utils.RBDHasWatchers(
415-
&image.Pool, &image.Name,
414+
ctx, &image.Pool, &image.Name,
416415
)
417-
if err == nil {
416+
if err != nil {
417+
ctx.Warnf("Unable to determine attachment state: %v", err)
418+
} else {
418419
if b {
419420
lsVolume.AttachmentState = types.VolumeUnavailable
420421
} else {

0 commit comments

Comments
 (0)