diff --git a/internal/rbd/rbd_attach.go b/internal/rbd/rbd_attach.go index 60fce5bbe..7ea8a9466 100644 --- a/internal/rbd/rbd_attach.go +++ b/internal/rbd/rbd_attach.go @@ -228,21 +228,19 @@ func setRbdNbdToolFeatures() { // returns mounter specific options. func parseMapOptions(mapOptions string) (string, string, error) { var krbdMapOptions, nbdMapOptions string - const ( - noKeyLength = 1 - validLength = 2 - ) for _, item := range strings.Split(mapOptions, ";") { var mounter, options string if item == "" { continue } - s := strings.Split(item, ":") - switch len(s) { - case noKeyLength: + s := strings.SplitN(item, ":", 2) + if len(s) == 1 { options = strings.TrimSpace(s[0]) krbdMapOptions = options - case validLength: + } else { + // options might also contain values delimited with ":", in this + // case mounter type MUST be specified. + // ex: krbd:read_from_replica=localize,crush_location=zone:zone1; mounter = strings.TrimSpace(s[0]) options = strings.TrimSpace(s[1]) switch strings.ToLower(mounter) { @@ -251,10 +249,8 @@ func parseMapOptions(mapOptions string) (string, string, error) { case accessTypeNbd: nbdMapOptions = options default: - return "", "", fmt.Errorf("unknown mounter type: %q", mounter) + return "", "", fmt.Errorf("unknown mounter type: %q, please specify mounter type", mounter) } - default: - return "", "", fmt.Errorf("badly formatted map/unmap options: %q", mapOptions) } } diff --git a/internal/rbd/rbd_attach_test.go b/internal/rbd/rbd_attach_test.go index 07749530d..7b1c6fa0a 100644 --- a/internal/rbd/rbd_attach_test.go +++ b/internal/rbd/rbd_attach_test.go @@ -60,18 +60,25 @@ func TestParseMapOptions(t *testing.T) { expectErr: "", }, { - name: "unknown mounter used", - mapOption: "xyz:xOp1,xOp2", + name: "with `:` delimiter used with in the options", + mapOption: "krbd:kOp1,kOp2=kOp21:kOp22;nbd:nOp1,nOp2=nOp21:nOp22", + expectKrbdOptions: "kOp1,kOp2=kOp21:kOp22", + expectNbdOptions: "nOp1,nOp2=nOp21:nOp22", + expectErr: "", + }, + { + name: "with `:` delimiter used with in the options, without mounter label", + mapOption: "kOp1,kOp2=kOp21:kOp22;nbd:nOp1,nOp2", expectKrbdOptions: "", expectNbdOptions: "", expectErr: "unknown mounter type", }, { - name: "bad formatted options", - mapOption: "nbd:nOp1:nOp2;", + name: "unknown mounter used", + mapOption: "xyz:xOp1,xOp2", expectKrbdOptions: "", expectNbdOptions: "", - expectErr: "badly formatted map/unmap options", + expectErr: "unknown mounter type", }, } for _, tt := range tests {