Skip to content

Commit

Permalink
chore: resolve blockdevice symlinks
Browse files Browse the repository at this point in the history
Resolve blockdevice symlinks before opening.
Also rekres.

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Apr 26, 2023
1 parent b4386f3 commit 076874a
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 18 deletions.
8 changes: 6 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2022-09-20T19:45:44Z by kres 255fc05.
# Generated on 2023-04-26T10:18:59Z by kres latest.

kind: pipeline
type: kubernetes
Expand Down Expand Up @@ -174,7 +174,7 @@ steps:

services:
- name: docker
image: docker:20.10-dind
image: docker:23.0-dind
entrypoint:
- dockerd
commands:
Expand Down Expand Up @@ -212,6 +212,10 @@ trigger:
exclude:
- renovate/*
- dependabot/*
event:
exclude:
- promote
- cron

---
kind: pipeline
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# syntax = docker/dockerfile-upstream:1.2.0-labs
# syntax = docker/dockerfile-upstream:1.5.2-labs

# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2023-02-13T11:37:21Z by kres latest.
# Generated on 2023-04-26T10:18:59Z by kres latest.

ARG TOOLCHAIN

# cleaned up specs and compiled versions
FROM scratch AS generate

# runs markdownlint
FROM docker.io/node:19.6.0-alpine3.16 AS lint-markdown
FROM docker.io/node:20.0.0-alpine3.16 AS lint-markdown
WORKDIR /src
RUN npm i -g [email protected]
RUN npm i [email protected]
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2023-02-13T11:37:21Z by kres latest.
# Generated on 2023-04-26T10:18:59Z by kres latest.

# common variables

Expand All @@ -13,13 +13,13 @@ WITH_RACE ?= false
REGISTRY ?= ghcr.io
USERNAME ?= siderolabs
REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME)
GOLANGCILINT_VERSION ?= v1.51.1
GOFUMPT_VERSION ?= v0.4.0
GOLANGCILINT_VERSION ?= v1.52.2
GOFUMPT_VERSION ?= v0.5.0
GO_VERSION ?= 1.20
GOIMPORTS_VERSION ?= v0.5.0
GOIMPORTS_VERSION ?= v0.8.0
PROTOBUF_GO_VERSION ?= 1.28.1
GRPC_GO_VERSION ?= 1.2.0
GRPC_GATEWAY_VERSION ?= 2.15.0
GRPC_GO_VERSION ?= 1.3.0
GRPC_GATEWAY_VERSION ?= 2.15.2
VTPROTOBUF_VERSION ?= 0.4.0
DEEPCOPY_VERSION ?= v0.5.5
GO_BUILDFLAGS ?=
Expand Down
6 changes: 1 addition & 5 deletions blockdevice/blkpg/blkpg_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ func inform(f *os.File, first, length uint64, n, op int32) error {
}
}

if err = f.Sync(); err != nil {
return err
}

return nil
return f.Sync()
})

if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions blockdevice/blockdevice_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"syscall"
"time"
"unsafe"
Expand Down Expand Up @@ -56,6 +57,11 @@ func Open(devname string, setters ...Option) (_ *BlockDevice, rerr error) { //no
err error
)

devname, err = filepath.EvalSymlinks(devname)
if err != nil {
return nil, fmt.Errorf("error resolving device symlink: %w", err)
}

if f, err = os.OpenFile(devname, opts.Mode, os.ModeDevice); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion blockdevice/blockdevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
)

func TestEmpty(t *testing.T) {
func TestEmpty(_ *testing.T) {
// added for accurate coverage estimation
//
// please remove it once any unit-test is added
Expand Down
13 changes: 13 additions & 0 deletions blockdevice/probe/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/stretchr/testify/suite"

"github.com/siderolabs/go-blockdevice/blockdevice"
"github.com/siderolabs/go-blockdevice/blockdevice/partition/gpt"
"github.com/siderolabs/go-blockdevice/blockdevice/probe"
"github.com/siderolabs/go-blockdevice/blockdevice/test"
Expand Down Expand Up @@ -66,6 +67,18 @@ func (suite *ProbeSuite) setSystemLabelEXT4(name string) {
suite.Require().NoError(cmd.Run())
}

func (suite *ProbeSuite) TestBlockDeviceWithSymlinkResolves() {
// Create a symlink to the block device
symlink := suite.Dev.Name() + ".link"
suite.Require().NoError(os.Symlink(suite.Dev.Name(), symlink))

defer os.Remove(symlink) //nolint:errcheck

bd, err := blockdevice.Open(symlink)
suite.Require().NoError(err)
suite.Require().Equal(suite.Dev.Name(), bd.Device().Name())
}

func (suite *ProbeSuite) TestDevForPartitionLabel() {
part12 := suite.addPartition("devpart12", 1024*1024, 12)
part32 := suite.addPartition("devpart32", 1024*1024*256, 32)
Expand Down
2 changes: 1 addition & 1 deletion blockdevice/serde/serde_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package serde_test

import "testing"

func TestEmpty(t *testing.T) {
func TestEmpty(_ *testing.T) {
// added for accurate coverage estimation
//
// please remove it once any unit-test is added
Expand Down

0 comments on commit 076874a

Please sign in to comment.