Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(upgrade): support v2 volume upgrade #474

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 1 addition & 56 deletions app/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"os/signal"
"path/filepath"
"regexp"
"strconv"
"strings"
"syscall"
Expand All @@ -26,10 +25,6 @@ import (
"google.golang.org/grpc/reflection"
"k8s.io/mount-utils"

commonTypes "github.com/longhorn/go-common-libs/types"
helpernvme "github.com/longhorn/go-spdk-helper/pkg/nvme"
helpertypes "github.com/longhorn/go-spdk-helper/pkg/types"
helperutil "github.com/longhorn/go-spdk-helper/pkg/util"
engineutil "github.com/longhorn/longhorn-engine/pkg/util"
spdk "github.com/longhorn/longhorn-spdk-engine/pkg/spdk"
spdkutil "github.com/longhorn/longhorn-spdk-engine/pkg/util"
Expand Down Expand Up @@ -115,52 +110,6 @@ func cleanup(pm *process.Manager) {
logrus.Errorf("Failed to clean up all processes for %s graceful shutdown", types.ProcessManagerGrpcService)
}

func getVolumeNameFromNQN(input string) (string, error) {
// compile a regular expression that matches ${name} between : and -e-
re, err := regexp.Compile(`:(.*)-e-`)
if err != nil {
return "", err
}
// find the first submatch of the input string
submatch := re.FindStringSubmatch(input)
if len(submatch) < 2 {
return "", fmt.Errorf("no name found in input")
}
// return the second element of the submatch, which is ${name}
return submatch[1], nil
}

func cleanupStaledNvmeAndDmDevices() error {
executor, err := helperutil.NewExecutor(commonTypes.ProcDirectory)
if err != nil {
return errors.Wrapf(err, "failed to create executor for cleaning up staled NVMe and dm devices")
}

subsystems, err := helpernvme.GetSubsystems(executor)
if err != nil {
return errors.Wrapf(err, "failed to get NVMe subsystems")
}
for _, sys := range subsystems {
logrus.Infof("Found NVMe subsystem %+v", sys)
if strings.HasPrefix(sys.NQN, helpertypes.NQNPrefix) {
dmDeviceName, err := getVolumeNameFromNQN(sys.NQN)
if err != nil {
return errors.Wrapf(err, "failed to get volume name from NQN %v", sys.NQN)
}
logrus.Infof("Removing dm device %v", dmDeviceName)
if err := helperutil.DmsetupRemove(dmDeviceName, false, false, executor); err != nil {
logrus.WithError(err).Warnf("Failed to remove dm device %v, will continue the cleanup", dmDeviceName)
}

logrus.Infof("Cleaning up NVMe subsystem %v: NQN %v", sys.Name, sys.NQN)
if err := helpernvme.DisconnectTarget(sys.NQN, executor); err != nil {
logrus.WithError(err).Warnf("Failed to disconnect NVMe subsystem %v: NQN %v, will continue the cleanup", sys.Name, sys.NQN)
}
}
}
return nil
}

func unfreezeFilesystems() error {
// We do not need to switch to the host mount namespace to get mount points here. Usually, longhorn-engine runs in a
// container that has / bind mounted to /host with at least HostToContainer (rslave) propagation.
Expand Down Expand Up @@ -209,11 +158,7 @@ func start(c *cli.Context) (err error) {
return err
}

if spdkEnabled {
if err := cleanupStaledNvmeAndDmDevices(); err != nil {
return err
}
} else {
if !spdkEnabled {
if err := unfreezeFilesystems(); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/google/uuid v1.6.0
github.com/longhorn/backupstore v0.0.0-20240706152841-78e2c8892f4e
github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e
github.com/longhorn/go-spdk-helper v0.0.0-20240702033003-35e00d17218f
github.com/longhorn/go-spdk-helper v0.0.0-20240708060539-de887e9cc6db
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240707085442-0bfac42c4aff
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240704075534-f807c4a293c6
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240708130427-1b50687fc568
github.com/longhorn/types v0.0.0-20240706151541-33cb010c3544
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e h1:0SiyvTu
github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e/go.mod h1:vX53A9KF4RHC1UTbEGouZHsZO6bwT3zk63l1hvwF5T8=
github.com/longhorn/go-iscsi-helper v0.0.0-20240706152726-9dbb9c7bdf30 h1:tTHysoIMIUt53dRqLtIo7AH0RRMr2P5Jy8DAMxDISO8=
github.com/longhorn/go-iscsi-helper v0.0.0-20240706152726-9dbb9c7bdf30/go.mod h1:Y4SlLQTYuOOMWlJNdFhTkM3MsXTmY/jkWj8jbuU7kOE=
github.com/longhorn/go-spdk-helper v0.0.0-20240702033003-35e00d17218f h1:CVv/UA0Jiq/w5p2Eb8d6KgwQr9TRMnpqkHZHQuZ0tIU=
github.com/longhorn/go-spdk-helper v0.0.0-20240702033003-35e00d17218f/go.mod h1:5dAfJz0UmWUqHgUtmAd/lFNA4yVbpLDgaMfin8UBv3w=
github.com/longhorn/go-spdk-helper v0.0.0-20240708060539-de887e9cc6db h1:wQRJNpZadsOD2w57Y3e0M0SnSp5IPIWFEF+1yoRzmrE=
github.com/longhorn/go-spdk-helper v0.0.0-20240708060539-de887e9cc6db/go.mod h1:BMhlxcEnrn0/jyO+9cMV1gWz2jkmeGFZLnGIqsH3lv0=
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240707085442-0bfac42c4aff h1:w8z+IYOHtvWEW7jZniVDX1vJGcGr4DIt2UmHeSxzXKU=
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240707085442-0bfac42c4aff/go.mod h1:u0TZ1221YusDYA+ExdVLjLid1Ps6JuJXgh9185l5D9Y=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240704075534-f807c4a293c6 h1:Q7wTQeHyraqMxyFQ36jB1a8z5pddakh/7LbsUr5qpW8=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240704075534-f807c4a293c6/go.mod h1:rGr1eYUryyGLxXGMFexCcj0VIFKetXr+0Balszp+raI=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240708130427-1b50687fc568 h1:FioK5fYJ2yXpVSaHWq13TvC6BMFcgaYWAYIjjuSYZ1c=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20240708130427-1b50687fc568/go.mod h1:XFF4wVEdM10/7fStU+mM0tx8zXEFurmIWHZjFvQyv/A=
github.com/longhorn/nsfilelock v0.0.0-20200723175406-fa7c83ad0003 h1:Jw9uANsGcHTxp6HcC++/vN17LfeuDmozHI2j6DoZf5E=
github.com/longhorn/nsfilelock v0.0.0-20200723175406-fa7c83ad0003/go.mod h1:0CLeXlf59Lg6C0kjLSDf47ft73Dh37CwymYRKWwAn04=
github.com/longhorn/sparse-tools v0.0.0-20240703010727-92451e38077a h1:+o63c0oh7ZNKeQdc0Hawfzz5vRa4LiDvLOtJYjegtnk=
Expand Down
16 changes: 9 additions & 7 deletions package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ FROM registry.suse.com/bci/bci-base:15.6 AS cbuilder

ARG ARCH=amd64

ENV LIBLONGHORN_COMMIT_ID 53d1c063b95efc8d949b095bd4bf04637230265f
ENV TGT_COMMIT_ID 3a8bc4823b5390e046f7aa8231ed262c0365c42c
ENV SPDK_COMMIT_ID a6478cde7e0cff2fb09992868308a7387aa5202a
ENV LIBJSONC_COMMIT_ID b4c371fa0cbc4dcbaccc359ce9e957a22988fb34
# nvme-cli 2.9.1
ENV NVME_CLI_COMMIT_ID b340fd7dcf1aef76f8d46ab28bef3c170d310887

RUN zypper -n addrepo --refresh https://download.opensuse.org/repositories/system:/snappy/SLE_15/system:snappy.repo && \
zypper -n addrepo --refresh https://download.opensuse.org/repositories/devel:libraries:c_c++/15.6/devel:libraries:c_c++.repo && \
zypper -n addrepo --refresh https://download.opensuse.org/repositories/devel:languages:python:Factory/15.6/devel:languages:python:Factory.repo && \
Expand All @@ -46,7 +53,6 @@ RUN zypper -n addrepo --refresh https://download.opensuse.org/repositories/syste
RUN zypper -n install cmake gcc xsltproc docbook-xsl-stylesheets git python311 python311-pip patchelf fuse3 libfuse3-3

# Build liblonghorn
ENV LIBLONGHORN_COMMIT_ID 53d1c063b95efc8d949b095bd4bf04637230265f
RUN cd /usr/src && \
git clone https://github.com/rancher/liblonghorn.git && \
cd liblonghorn && \
Expand All @@ -55,17 +61,15 @@ RUN cd /usr/src && \
make install

# Build TGT
ENV TGT_COMMIT_ID 3a8bc4823b5390e046f7aa8231ed262c0365c42c
RUN cd /usr/src && \
git clone https://github.com/rancher/tgt.git && \
cd tgt && \
git checkout ${TGT_COMMIT_ID} && \
make; \
make install

# Build SPDK
# Build spdk
ENV SPDK_DIR /usr/src/spdk
ENV SPDK_COMMIT_ID a6478cde7e0cff2fb09992868308a7387aa5202a
RUN git clone https://github.com/longhorn/spdk.git ${SPDK_DIR} --recursive && \
cd ${SPDK_DIR} && \
git checkout ${SPDK_COMMIT_ID} && \
Expand All @@ -88,7 +92,6 @@ RUN git clone https://github.com/longhorn/spdk.git ${SPDK_DIR} --recursive && \
fi

# Build libjson-c-devel
ENV LIBJSONC_COMMIT_ID b4c371fa0cbc4dcbaccc359ce9e957a22988fb34
RUN cd /usr/src && \
git clone https://github.com/json-c/json-c.git && \
cd json-c && \
Expand All @@ -99,9 +102,8 @@ RUN cd /usr/src && \
make && \
make install

# Build nvme-cli 2.9.1
# Build nvme-cli
ENV NVME_CLI_DIR /usr/src/nvme-cli
ENV NVME_CLI_COMMIT_ID b340fd7dcf1aef76f8d46ab28bef3c170d310887
RUN git clone https://github.com/linux-nvme/nvme-cli.git ${NVME_CLI_DIR} && \
cd ${NVME_CLI_DIR} && \
git checkout ${NVME_CLI_COMMIT_ID} && \
Expand Down
24 changes: 14 additions & 10 deletions pkg/api/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,24 @@ func RPCToInstanceList(obj *rpc.InstanceListResponse) map[string]*Instance {
}

type InstanceStatus struct {
State string `json:"state"`
ErrorMsg string `json:"errorMsg"`
Conditions map[string]bool `json:"conditions"`
PortStart int32 `json:"portStart"`
PortEnd int32 `json:"portEnd"`
State string `json:"state"`
ErrorMsg string `json:"errorMsg"`
Conditions map[string]bool `json:"conditions"`
PortStart int32 `json:"portStart"`
PortEnd int32 `json:"portEnd"`
TargetPortStart int32 `json:"targetPortStart"`
TargetPortEnd int32 `json:"targetPortEnd"`
}

func RPCToInstanceStatus(obj *rpc.InstanceStatus) InstanceStatus {
return InstanceStatus{
State: obj.State,
ErrorMsg: obj.ErrorMsg,
Conditions: obj.Conditions,
PortStart: obj.PortStart,
PortEnd: obj.PortEnd,
State: obj.State,
ErrorMsg: obj.ErrorMsg,
Conditions: obj.Conditions,
PortStart: obj.PortStart,
PortEnd: obj.PortEnd,
TargetPortStart: obj.TargetPortStart,
TargetPortEnd: obj.TargetPortEnd,
}
}

Expand Down
Loading