Skip to content

Commit

Permalink
Reorder struct variables and move up cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Luciano Lo Giudice <[email protected]>
  • Loading branch information
lmlg committed Sep 27, 2023
1 parent 285c26b commit c694d59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions microceph/api/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func cmdDisksPost(s *state.State, r *http.Request) response.Response {
mu.Lock()
defer mu.Unlock()

data := types.DiskParameter{req.Path, req.Wipe, req.Encrypt}
data := types.DiskParameter{req.Path, req.Encrypt, req.Wipe}
if req.WALDev != nil {
wal = &types.DiskParameter{*req.WALDev, req.WALWipe, req.WALEncrypt}
wal = &types.DiskParameter{*req.WALDev, req.WALEncrypt, req.WALWipe}
}
if req.DBDev != nil {
db = &types.DiskParameter{*req.DBDev, req.DBWipe, req.DBEncrypt}
db = &types.DiskParameter{*req.DBDev, req.DBEncrypt, req.DBWipe}
}

err = ceph.AddOSD(s, data, wal, db)
Expand Down
18 changes: 9 additions & 9 deletions microceph/ceph/osd.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,15 @@ func AddOSD(s *state.State, data types.DiskParameter, wal *types.DiskParameter,

logger.Debugf("Created disk record for osd.%d", nr)

// if we fail later, make sure we free up the record
revert.Add(func() {
os.RemoveAll(osdDataPath)
s.Database.Transaction(s.Context, func(ctx context.Context, tx *sql.Tx) error {
database.DeleteDisk(ctx, tx, s.Name(), oldPath)
return nil
})
})

dataPath := filepath.Join(os.Getenv("SNAP_COMMON"), "data")
osdDataPath := filepath.Join(dataPath, "osd", fmt.Sprintf("ceph-%d", nr))

Expand All @@ -394,15 +403,6 @@ func AddOSD(s *state.State, data types.DiskParameter, wal *types.DiskParameter,
return fmt.Errorf("Failed to prepare data device: %w", err)
}

// if we fail later, make sure we free up the record
revert.Add(func() {
os.RemoveAll(osdDataPath)
s.Database.Transaction(s.Context, func(ctx context.Context, tx *sql.Tx) error {
database.DeleteDisk(ctx, tx, s.Name(), oldPath)
return nil
})
})

// Generate keyring.
err = genAuth(filepath.Join(osdDataPath, "keyring"), fmt.Sprintf("osd.%d", nr), []string{"mgr", "allow profile osd"}, []string{"mon", "allow profile osd"}, []string{"osd", "allow *"})
if err != nil {
Expand Down

0 comments on commit c694d59

Please sign in to comment.