Skip to content

Commit

Permalink
API for quiesceing io on a subvolume.
Browse files Browse the repository at this point in the history
Signed-off-by: Manish <myathnal@redhat.com>
  • Loading branch information
manishym committed Feb 8, 2024
1 parent 780f701 commit e75ca1d
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
111 changes: 111 additions & 0 deletions cephfs/admin/subvolume.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package admin

import "fmt"

// this is the internal type used to create JSON for ceph.
// See SubVolumeOptions for the type that users of the library
// interact with.
Expand Down Expand Up @@ -423,3 +425,112 @@ func (fsa *FSAdmin) UnprotectSubVolumeSnapshot(volume, group, subvolume, name st
}
return fsa.marshalMgrCommand(m).FilterDeprecated().NoData().End()
}

type MyFloat float64

func (mf MyFloat) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("%.2f", float64(mf))), nil
}

type SubVolumeQuiesceFields struct {
Prefix string `json:"prefix"`
VolName string `json:"vol_name"`
GroupName string `json:"group_name,omitempty"`
Members []string `json:"members,omitempty"`
SetId string `json:"set_id,omitempty"`
Timeout MyFloat `json:"timeout,omitempty"`
Expiration MyFloat `json:"expiration,omitempty"`
AwaitFor MyFloat `json:"await_for,omitempty"`
Await bool `json:"await,omitempty"`
IfVersion int `json:"if_version,omitempty"`
Include bool `json:"include,omitempty"`
Exclude bool `json:"exclude,omitempty"`
Reset bool `json:"reset,omitempty"`
Release bool `json:"release,omitempty"`
Query bool `json:"query,omitempty"`
All bool `json:"all,omitempty"`
Cancel bool `json:"cancel,omitempty"`
}

type SubVolumeQuiesceOptions struct {
Timeout MyFloat
Expiration MyFloat
AwaitFor MyFloat
Await bool
IfVersion int
Include bool
Exclude bool
Reset bool
Release bool
Query bool
All bool
Cancel bool
}

func (o *SubVolumeQuiesceOptions) toFields(volume, group string, subvolumes []string, set_id string) *SubVolumeQuiesceFields {
return &SubVolumeQuiesceFields{
Prefix: "fs subvolume quiesce",
VolName: volume,
GroupName: group,
Members: subvolumes,
SetId: set_id,
Timeout: o.Timeout,
Expiration: o.Expiration,
AwaitFor: o.AwaitFor,
Await: o.Await,
IfVersion: o.IfVersion,
Include: o.Include,
Exclude: o.Exclude,
Reset: o.Reset,
Release: o.Release,
Query: o.Query,
All: o.All,
Cancel: o.Cancel,
}
}

type QuiesceInfo struct {
DbVersion int `json:"db_version"`
AgeRef float64 `json:"age_ref"`
State struct {
Name string `json:"name"`
Age float64 `json:"age"`
} `json:"state"`
Timeout float64 `json:"timeout"`
Expiration float64 `json:"expiration"`
Members map[string]struct {
Excluded bool `json:"excluded"`
State struct {
Name string `json:"name"`
Age float64 `json:"age"`
} `json:"state"`
} `json:"members"`
}

type SubVolumeQuiesceInfo struct {
Epoch int `json:"epoch"`
DbVersion int `json:"db_version"`
Sets map[string]QuiesceInfo `json:"sets"`
}

func parseSubVolumeQuiesceInfo(res response) (*SubVolumeQuiesceInfo, error) {
var info SubVolumeQuiesceInfo
if err := res.NoStatus().Unmarshal(&info).End(); err != nil {
return nil, err
}
return &info, nil
}

// SubVolumeQuiesce will quiesce the specified subvolume.
// Quiescing a subvolume will prevent new writes to the subvolume.
// Similar To:
//
// ceph fs subvolume quiesce <volume>
func (fsa *FSAdmin) SubVolumeQuiesce(volume, group string, subvolumes []string, set_id string, o *SubVolumeQuiesceOptions) (*SubVolumeQuiesceInfo, error) {
if o == nil {
o = &SubVolumeQuiesceOptions{}
}
f := o.toFields(volume, group, subvolumes, set_id)

return parseSubVolumeQuiesceInfo(fsa.marshalMgrCommand(f))
}
30 changes: 30 additions & 0 deletions cephfs/admin/subvolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,3 +688,33 @@ func TestSubVolumeSnapshotInfo(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, sinfo)
}

func TestSubvolumeQuiesce(t *testing.T) {
fsa := getFSAdmin(t)
volume := "cephfs"
group := NoGroup
fsa.CreateSubVolume(volume, group, "quiesceMe", nil)
defer func() {
err := fsa.RemoveSubVolume(volume, group, "quiesceMe")
assert.NoError(t, err)
}()
ret, err := fsa.SubVolumeQuiesce(volume, group, []string{"sub1"}, "", nil)
assert.NoError(t, err)
for _, val := range ret.Sets {
assert.Equal(t, 0.0, val.Timeout)
}
o := &SubVolumeQuiesceOptions{}
o.Timeout = 10.7
ret, err = fsa.SubVolumeQuiesce(volume, group, []string{"sub1"}, "", o)
assert.NoError(t, err)
for _, val := range ret.Sets {
assert.Equal(t, 10.7, val.Timeout)
}
o.Expiration = 15.2
ret, err = fsa.SubVolumeQuiesce(volume, group, []string{"sub1"}, "", o)
assert.NoError(t, err)
for _, val := range ret.Sets {
assert.Equal(t, 15.2, val.Expiration)
assert.Equal(t, 10.7, val.Timeout)
}
}

0 comments on commit e75ca1d

Please sign in to comment.