diff --git a/microceph/ceph/osd.go b/microceph/ceph/osd.go index ce31c2dd..2feac183 100644 --- a/microceph/ceph/osd.go +++ b/microceph/ceph/osd.go @@ -376,7 +376,13 @@ 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 + // Keep the old path in case it changes after encrypting. + oldPath := data.Path + + dataPath := filepath.Join(os.Getenv("SNAP_COMMON"), "data") + osdDataPath := filepath.Join(dataPath, "osd", fmt.Sprintf("ceph-%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 { @@ -385,12 +391,6 @@ func AddOSD(s *state.State, data types.DiskParameter, wal *types.DiskParameter, }) }) - dataPath := filepath.Join(os.Getenv("SNAP_COMMON"), "data") - osdDataPath := filepath.Join(dataPath, "osd", fmt.Sprintf("ceph-%d", nr)) - - // Keep the old path in case it changes after encrypting. - oldPath := data.Path - // Create directory. err = os.MkdirAll(osdDataPath, 0700) if err != nil {