Skip to content

Commit e0df1f1

Browse files
committed
fix unablility of mounting ext disk read-only
1 parent db2d6b7 commit e0df1f1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/gce-pd-csi-driver/node.go

+18
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const (
6060
volumeLimitBig int64 = 127
6161
defaultLinuxFsType = "ext4"
6262
defaultWindowsFsType = "ntfs"
63+
fsTypeExt3 = "ext3"
6364
)
6465

6566
func getDefaultFsType() string {
@@ -311,8 +312,25 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
311312
return &csi.NodeStageVolumeResponse{}, nil
312313
}
313314

315+
readonly, _ := getReadOnlyFromCapability(volumeCapability)
316+
if readonly {
317+
options = append(options, "ro")
318+
klog.V(4).Infof("CSI volume is read-only, mounting with extra option ro")
319+
}
320+
314321
err = formatAndMount(devicePath, stagingTargetPath, fstype, options, ns.Mounter)
315322
if err != nil {
323+
// ext4 and ext3 replays the journal which needs write permission. So noload option stops that
324+
if readonly && (fstype == defaultLinuxFsType || fstype == fsTypeExt3) {
325+
klog.V(4).Infof("Failed to mount CSI volume read-only, retry mounting with extra option noload")
326+
327+
options = append(options, "noload")
328+
err = formatAndMount(devicePath, stagingTargetPath, fstype, options, ns.Mounter)
329+
if err == nil {
330+
klog.V(4).Infof("NodeStageVolume succeeded with \"noload\" option on %v to %s", volumeID, stagingTargetPath)
331+
return &csi.NodeStageVolumeResponse{}, nil
332+
}
333+
}
316334
return nil, status.Error(codes.Internal,
317335
fmt.Sprintf("Failed to format and mount device from (%q) to (%q) with fstype (%q) and options (%q): %v",
318336
devicePath, stagingTargetPath, fstype, options, err))

0 commit comments

Comments
 (0)