Skip to content

Commit 9d4f213

Browse files
aledbfcsweichel
authored andcommitted
Bind mounting /workspace in ring1 only if not running FWB
1 parent 295572e commit 9d4f213

File tree

7 files changed

+124
-68
lines changed

7 files changed

+124
-68
lines changed

components/workspacekit/cmd/rings.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ var ring0Cmd = &cobra.Command{
9696
cmd.Stdin = os.Stdin
9797
cmd.Stdout = os.Stdout
9898
cmd.Stderr = os.Stderr
99-
cmd.Env = append(os.Environ(), "WORKSPACEKIT_FSSHIFT="+prep.FsShift.String())
99+
cmd.Env = append(os.Environ(),
100+
"WORKSPACEKIT_FSSHIFT="+prep.FsShift.String(),
101+
fmt.Sprintf("WORKSPACEKIT_FULL_WORKSPACE_BACKUP=%v", prep.FullWorkspaceBackup),
102+
)
100103

101104
if err := cmd.Start(); err != nil {
102105
log.WithError(err).Error("failed to start ring0")
@@ -256,14 +259,20 @@ var ring1Cmd = &cobra.Command{
256259
mnts = append(mnts,
257260
mnte{Target: "/sys", Flags: unix.MS_BIND | unix.MS_REC},
258261
mnte{Target: "/dev", Flags: unix.MS_BIND | unix.MS_REC},
259-
// TODO(cw): only mount /workspace if it's in the mount table, i.e. this isn't an FWB workspace
260-
mnte{Target: "/workspace", Flags: unix.MS_BIND | unix.MS_REC},
261262
mnte{Target: "/etc/hosts", Flags: unix.MS_BIND | unix.MS_REC},
262263
mnte{Target: "/etc/hostname", Flags: unix.MS_BIND | unix.MS_REC},
263264
mnte{Target: "/etc/resolv.conf", Flags: unix.MS_BIND | unix.MS_REC},
264265
mnte{Target: "/tmp", Source: "tmpfs", FSType: "tmpfs"},
265266
)
266267

268+
// FWB workspaces do not require mounting /workspace
269+
// if that is done, the backup will not contain any change in the directory
270+
if os.Getenv("WORKSPACEKIT_FULL_WORKSPACE_BACKUP") != "true" {
271+
mnts = append(mnts,
272+
mnte{Target: "/workspace", Flags: unix.MS_BIND | unix.MS_REC},
273+
)
274+
}
275+
267276
for _, m := range mnts {
268277
dst := filepath.Join(ring2Root, m.Target)
269278
_ = os.MkdirAll(dst, 0644)

components/ws-daemon-api/go/workspace_daemon.pb.go

Lines changed: 72 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/ws-daemon-api/typescript/src/workspace_daemon_pb.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export namespace PrepareForUserNSRequest {
3232
export class PrepareForUserNSResponse extends jspb.Message {
3333
getFsShift(): FSShiftMethod;
3434
setFsShift(value: FSShiftMethod): PrepareForUserNSResponse;
35+
getFullWorkspaceBackup(): boolean;
36+
setFullWorkspaceBackup(value: boolean): PrepareForUserNSResponse;
3537

3638
serializeBinary(): Uint8Array;
3739
toObject(includeInstance?: boolean): PrepareForUserNSResponse.AsObject;
@@ -46,6 +48,7 @@ export class PrepareForUserNSResponse extends jspb.Message {
4648
export namespace PrepareForUserNSResponse {
4749
export type AsObject = {
4850
fsShift: FSShiftMethod,
51+
fullWorkspaceBackup: boolean,
4952
}
5053
}
5154

components/ws-daemon-api/typescript/src/workspace_daemon_pb.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ proto.iws.PrepareForUserNSResponse.prototype.toObject = function(opt_includeInst
397397
*/
398398
proto.iws.PrepareForUserNSResponse.toObject = function(includeInstance, msg) {
399399
var f, obj = {
400-
fsShift: jspb.Message.getFieldWithDefault(msg, 1, 0)
400+
fsShift: jspb.Message.getFieldWithDefault(msg, 1, 0),
401+
fullWorkspaceBackup: jspb.Message.getBooleanFieldWithDefault(msg, 2, false)
401402
};
402403

403404
if (includeInstance) {
@@ -438,6 +439,10 @@ proto.iws.PrepareForUserNSResponse.deserializeBinaryFromReader = function(msg, r
438439
var value = /** @type {!proto.iws.FSShiftMethod} */ (reader.readEnum());
439440
msg.setFsShift(value);
440441
break;
442+
case 2:
443+
var value = /** @type {boolean} */ (reader.readBool());
444+
msg.setFullWorkspaceBackup(value);
445+
break;
441446
default:
442447
reader.skipField();
443448
break;
@@ -474,6 +479,13 @@ proto.iws.PrepareForUserNSResponse.serializeBinaryToWriter = function(message, w
474479
f
475480
);
476481
}
482+
f = message.getFullWorkspaceBackup();
483+
if (f) {
484+
writer.writeBool(
485+
2,
486+
f
487+
);
488+
}
477489
};
478490

479491

@@ -495,6 +507,24 @@ proto.iws.PrepareForUserNSResponse.prototype.setFsShift = function(value) {
495507
};
496508

497509

510+
/**
511+
* optional bool full_workspace_backup = 2;
512+
* @return {boolean}
513+
*/
514+
proto.iws.PrepareForUserNSResponse.prototype.getFullWorkspaceBackup = function() {
515+
return /** @type {boolean} */ (jspb.Message.getBooleanFieldWithDefault(this, 2, false));
516+
};
517+
518+
519+
/**
520+
* @param {boolean} value
521+
* @return {!proto.iws.PrepareForUserNSResponse} returns this
522+
*/
523+
proto.iws.PrepareForUserNSResponse.prototype.setFullWorkspaceBackup = function(value) {
524+
return jspb.Message.setProto3BooleanField(this, 2, value);
525+
};
526+
527+
498528

499529

500530

components/ws-daemon-api/workspace_daemon.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ service InWorkspaceService {
3535
message PrepareForUserNSRequest {}
3636
message PrepareForUserNSResponse {
3737
FSShiftMethod fs_shift = 1;
38+
bool full_workspace_backup = 2;
3839
}
3940

4041
// FSShiftMethod describes the means by which we establish the ID shift for

components/ws-daemon/pkg/content/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func (s *WorkspaceService) uploadWorkspaceContent(ctx context.Context, sess *ses
468468
)
469469
}
470470

471-
err = BuildTarbal(ctx, loc, tmpf.Name(),sess.FullWorkspaceBackup, opts...)
471+
err = BuildTarbal(ctx, loc, tmpf.Name(), sess.FullWorkspaceBackup, opts...)
472472
if err != nil {
473473
return
474474
}

components/ws-daemon/pkg/iws/iws.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ func (wbs *InWorkspaceServiceServer) PrepareForUserNS(ctx context.Context, req *
254254
}
255255

256256
return &api.PrepareForUserNSResponse{
257-
FsShift: api.FSShiftMethod_FUSE,
257+
FsShift: api.FSShiftMethod_FUSE,
258+
FullWorkspaceBackup: wbs.Session.FullWorkspaceBackup,
258259
}, nil
259260
}
260261

@@ -278,7 +279,8 @@ func (wbs *InWorkspaceServiceServer) PrepareForUserNS(ctx context.Context, req *
278279
}
279280

280281
return &api.PrepareForUserNSResponse{
281-
FsShift: api.FSShiftMethod_SHIFTFS,
282+
FsShift: api.FSShiftMethod_SHIFTFS,
283+
FullWorkspaceBackup: wbs.Session.FullWorkspaceBackup,
282284
}, nil
283285
}
284286

0 commit comments

Comments
 (0)