Skip to content

ws-daemon: Soft limit of the xfs at first to ensure that the contents can be restored #10519

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

Merged
merged 1 commit into from
Jun 8, 2022
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
18 changes: 14 additions & 4 deletions components/ws-daemon/pkg/content/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func workspaceLifecycleHooks(cfg Config, kubernetesNamespace string, workspaceEx
hookSetupWorkspaceLocation,
startIWS, // workspacekit is waiting for starting IWS, so it needs to start as soon as possible.
hookSetupRemoteStorage(cfg),
// When starting a workspace, use soft limit for the following reason to ensure content is restored
// - workspacekit needs to generate some temporary file when starting a workspace
// - when extracting tar file, tar command create some symlinks following a original content
hookInstallQuota(xfs, false),
},
session.WorkspaceReady: {
Expand Down Expand Up @@ -98,17 +101,24 @@ func hookInstallQuota(xfs *quota.XFS, isHard bool) session.WorkspaceLivecycleHoo
if xfs == nil {
return nil
}
size := quota.Size(ws.StorageQuota)
if size == 0 {

if ws.StorageQuota == 0 {
return nil
}

size := quota.Size(ws.StorageQuota)

var (
prj int
err error
)
if ws.XFSProjectID != 0 {
xfs.RegisterProject(ws.XFSProjectID)
return nil
prj, err = xfs.SetQuotaWithPrjId(ws.Location, size, ws.XFSProjectID, isHard)
} else {
prj, err = xfs.SetQuota(ws.Location, size, isHard)
}

prj, err := xfs.SetQuota(ws.Location, size, isHard)
if err != nil {
log.WithFields(ws.OWI()).WithError(err).Warn("cannot enforce workspace size limit")
}
Expand Down
11 changes: 10 additions & 1 deletion components/ws-daemon/pkg/quota/xfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ func (xfs *XFS) SetQuota(path string, quota Size, isHard bool) (projectID int, e
}
}()

_, err = xfs.SetQuotaWithPrjId(path, quota, prjID, isHard)
if err != nil {
return 0, err
}

return prjID, nil
}

func (xfs *XFS) SetQuotaWithPrjId(path string, quota Size, prjID int, isHard bool) (projectID int, err error) {
_, err = xfs.exec(xfs.Dir, fmt.Sprintf("project -s -d 1 -p %s %d", path, prjID))
if err != nil {
return 0, err
Expand All @@ -121,7 +130,7 @@ func (xfs *XFS) SetQuota(path string, quota Size, isHard bool) (projectID int, e
if isHard {
_, err = xfs.exec(xfs.Dir, fmt.Sprintf("limit -p bhard=%d %d", quota, prjID))
} else {
_, err = xfs.exec(xfs.Dir, fmt.Sprintf("limit -p bsoft=%d bhard=%d %d", quota, quota, prjID))
_, err = xfs.exec(xfs.Dir, fmt.Sprintf("limit -p bsoft=%d %d", quota, prjID))
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion components/ws-daemon/pkg/quota/xfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestSetQuota(t *testing.T) {
ProjectIDs: []int{1000},
Execs: []string{
"project -s -d 1 -p /foo 1000",
"limit -p bsoft=102400 bhard=102400 1000",
"limit -p bsoft=102400 1000",
},
},
},
Expand Down