Skip to content

Commit b9206e2

Browse files
authored
Readonly share support
1 parent f6e7494 commit b9206e2

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

lib/runners/crosvm.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ in {
100100
]
101101
) volumes
102102
++
103-
builtins.concatMap ({ proto, tag, source, socket, ... }: {
103+
builtins.concatMap ({ proto, tag, source, socket, readOnly, ... }: {
104104
"virtiofs" = [
105105
"--vhost-user" "type=fs,socket=${socket}"
106106
];
107-
"9p" = [
107+
"9p" = if readOnly then
108+
throw "Readonly 9p share is not supported"
109+
else [
108110
"--shared-dir" "${source}:${tag}:type=p9"
109111
];
110112
}.${proto}) shares

lib/runners/kvmtool.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ in {
5959
]
6060
) volumes
6161
++
62-
builtins.concatMap ({ proto, source, tag, ... }:
62+
builtins.concatMap ({ proto, source, tag, readOnly, ... }:
6363
if proto == "9p"
64-
then [
64+
then if readOnly then
65+
throw "kvmtool does not support readonly 9p share"
66+
else [
6567
"--9p" (lib.escapeShellArg "${source},${tag}")
6668
] else throw "virtiofs shares not implemented for kvmtool"
6769
) shares

lib/runners/qemu.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,13 @@ lib.warnIf (mem == 2048) ''
253253
"-numa" "node,memdev=mem"
254254
"-object" "memory-backend-memfd,id=mem,size=${toString mem}M,share=on"
255255
]) ++
256-
builtins.concatMap ({ proto, index, socket, source, tag, securityModel, ... }: {
256+
builtins.concatMap ({ proto, index, socket, source, tag, securityModel, readOnly, ... }: {
257257
"virtiofs" = [
258258
"-chardev" "socket,id=fs${toString index},path=${socket}"
259259
"-device" "vhost-user-fs-${devType},chardev=fs${toString index},tag=${tag}"
260260
];
261261
"9p" = [
262-
"-fsdev" "local,id=fs${toString index},path=${source},security_model=${securityModel}"
262+
"-fsdev" "local,id=fs${toString index},path=${source},security_model=${securityModel},readonly=${lib.boolToString readOnly}"
263263
"-device" "virtio-9p-${devType},fsdev=fs${toString index},mount_tag=${tag}"
264264
];
265265
}.${proto}) (enumerate 0 shares)

nixos-modules/microvm/options.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ in
371371
description = "Protocol for this share";
372372
default = "9p";
373373
};
374+
readOnly = mkOption {
375+
type = bool;
376+
description = "Turn off write access";
377+
default = false;
378+
};
374379
};
375380
}));
376381
};

nixos-modules/microvm/virtiofsd/default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ in
2828
events = "PROCESS_STATE";
2929
};
3030
} // builtins.listToAttrs (
31-
map ({ tag, socket, source, ... }: {
31+
map ({ tag, socket, source, readOnly, ... }: {
3232
name = "program:virtiofsd-${tag}";
3333
value = {
3434
stderr_syslog = true;
@@ -55,6 +55,7 @@ in
5555
${lib.optionalString (config.microvm.hypervisor == "crosvm")
5656
"--tag=${tag}"
5757
} \
58+
${lib.optionalString readOnly "--readonly"} \
5859
${lib.concatStringsSep " " config.microvm.virtiofsd.extraArgs}
5960
'';
6061
};

0 commit comments

Comments
 (0)