add function to s3
This commit is contained in:
@@ -730,10 +730,36 @@ func (s *ZFSService) CreateDataset(ctx context.Context, poolName string, req Cre
|
||||
// Construct full dataset name
|
||||
fullName := poolName + "/" + req.Name
|
||||
|
||||
// For filesystem datasets, create mount directory if mount point is provided
|
||||
if req.Type == "filesystem" && req.MountPoint != "" {
|
||||
// Clean and validate mount point path
|
||||
mountPath := filepath.Clean(req.MountPoint)
|
||||
// Get pool mount point to validate dataset mount point is within pool directory
|
||||
poolMountPoint := fmt.Sprintf("/opt/calypso/data/pool/%s", poolName)
|
||||
var mountPath string
|
||||
|
||||
// For filesystem datasets, validate and set mount point
|
||||
if req.Type == "filesystem" {
|
||||
if req.MountPoint != "" {
|
||||
// User provided mount point - validate it's within pool directory
|
||||
mountPath = filepath.Clean(req.MountPoint)
|
||||
|
||||
// Check if mount point is within pool mount point directory
|
||||
poolMountAbs, err := filepath.Abs(poolMountPoint)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to resolve pool mount point: %w", err)
|
||||
}
|
||||
|
||||
mountPathAbs, err := filepath.Abs(mountPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to resolve mount point: %w", err)
|
||||
}
|
||||
|
||||
// Check if mount path is within pool mount point directory
|
||||
relPath, err := filepath.Rel(poolMountAbs, mountPathAbs)
|
||||
if err != nil || strings.HasPrefix(relPath, "..") {
|
||||
return nil, fmt.Errorf("mount point must be within pool directory: %s (pool mount: %s)", mountPath, poolMountPoint)
|
||||
}
|
||||
} else {
|
||||
// No mount point provided - use default: /opt/calypso/data/pool/<pool-name>/<dataset-name>/
|
||||
mountPath = filepath.Join(poolMountPoint, req.Name)
|
||||
}
|
||||
|
||||
// Check if directory already exists
|
||||
if info, err := os.Stat(mountPath); err == nil {
|
||||
@@ -782,9 +808,9 @@ func (s *ZFSService) CreateDataset(ctx context.Context, poolName string, req Cre
|
||||
args = append(args, "-o", fmt.Sprintf("compression=%s", req.Compression))
|
||||
}
|
||||
|
||||
// Set mount point if provided (only for filesystems, not volumes)
|
||||
if req.Type == "filesystem" && req.MountPoint != "" {
|
||||
args = append(args, "-o", fmt.Sprintf("mountpoint=%s", req.MountPoint))
|
||||
// Set mount point for filesystems (always set, either user-provided or default)
|
||||
if req.Type == "filesystem" {
|
||||
args = append(args, "-o", fmt.Sprintf("mountpoint=%s", mountPath))
|
||||
}
|
||||
|
||||
// Execute zfs create
|
||||
|
||||
Reference in New Issue
Block a user