Skip to content

Commit 058f951

Browse files
author
Xun Chen
committed
Extend tcmu dev_config to support optional device ID
Signed-off-by: Xun Chen <xunchen@hust.edu.cn>
1 parent b70ba9c commit 058f951

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

cmd/overlaybd-attacher/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ func main() {
5959
Usage: "Enable verbose logging",
6060
Aliases: []string{"v"},
6161
},
62+
&cli.BoolFlag{
63+
Name: "with-devid",
64+
Usage: "Include devid in dev_config",
65+
Value: false,
66+
},
6267
},
6368
Action: attachAction,
6469
},
@@ -96,6 +101,7 @@ func attachAction(c *cli.Context) error {
96101
tenant := -1
97102
configPath := c.String("config")
98103
retryCount := 5
104+
withDevID := c.Bool("with-devid")
99105

100106
if _, err := os.Stat(configPath); err != nil {
101107
return fmt.Errorf("config file does not exist: %s: %w", configPath, err)
@@ -128,9 +134,9 @@ func attachAction(c *cli.Context) error {
128134
}
129135

130136
ctx := context.Background()
131-
params := snapshot.NewAttachDeviceParams(id, tenant, absConfigPath, resultFile)
137+
params := snapshot.NewAttachDeviceParams(id, tenant, absConfigPath, resultFile, withDevID)
132138

133-
logrus.Infof("attaching device: id=%s, tenant=%d, config=%s, resultFile=%s", id, tenant, absConfigPath, resultFile)
139+
logrus.Infof("attaching device: id=%s, tenant=%d, config=%s, resultFile=%s, withDevID=%t", id, tenant, absConfigPath, resultFile, withDevID)
134140

135141
var devName string
136142
var lastErr error

pkg/snapshot/storage.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ type AttachDeviceParams struct {
7878

7979
configPath string // config.v1.json
8080
resultFile string // init-debug.log
81+
withDevID bool
8182
}
8283

83-
func NewAttachDeviceParams(id string, tenant int, configPath string, resultFile string) *AttachDeviceParams {
84+
func NewAttachDeviceParams(id string, tenant int, configPath string, resultFile string, withDevID bool) *AttachDeviceParams {
8485
return &AttachDeviceParams{
8586
id: id,
8687
tenant: tenant,
8788
configPath: configPath,
8889
resultFile: resultFile,
90+
withDevID: withDevID,
8991
}
9092
}
9193

@@ -299,8 +301,14 @@ func AttachDevice(ctx context.Context, params *AttachDeviceParams) (devName stri
299301
}
300302
}()
301303

302-
if err = os.WriteFile(path.Join(targetPath, "control"), ([]byte)(fmt.Sprintf("dev_config=overlaybd/%s", configPath)), 0666); err != nil {
303-
return devName, fmt.Errorf("failed to write target dev_config for %s: dev_config=overlaybd/%s: %w", targetPath, configPath, err)
304+
if params.withDevID {
305+
if err = os.WriteFile(path.Join(targetPath, "control"), ([]byte)(fmt.Sprintf("dev_config=overlaybd/%s;%s", configPath, snID)), 0666); err != nil {
306+
return devName, fmt.Errorf("failed to write target dev_config for %s: dev_config=overlaybd/%s;%s: %w", targetPath, configPath, snID, err)
307+
}
308+
} else {
309+
if err = os.WriteFile(path.Join(targetPath, "control"), ([]byte)(fmt.Sprintf("dev_config=overlaybd/%s", configPath)), 0666); err != nil {
310+
return devName, fmt.Errorf("failed to write target dev_config for %s: dev_config=overlaybd/%s: %w", targetPath, configPath, err)
311+
}
304312
}
305313

306314
err = os.WriteFile(path.Join(targetPath, "control"), ([]byte)(fmt.Sprintf("max_data_area_mb=%d", obdMaxDataAreaMB)), 0666)
@@ -455,6 +463,7 @@ func (o *snapshotter) attachAndMountBlockDevice(ctx context.Context, snID string
455463
o.tenant,
456464
configPath,
457465
o.overlaybdInitDebuglogPath(snID),
466+
false,
458467
),
459468
)
460469
if err != nil {

script/config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
"runtimeType": "containerd",
77
"logReportCaller": false,
88
"autoRemoveDev": false,
9-
"mirrorRegistry": []
9+
"mirrorRegistry": [],
10+
"experimental": {
11+
"enable": true
12+
}
1013
}

0 commit comments

Comments
 (0)