|
4 | 4 | "context" |
5 | 5 | "fmt" |
6 | 6 | "os" |
7 | | - "strings" |
8 | 7 | "time" |
9 | 8 |
|
10 | 9 | "github.com/container-storage-interface/spec/lib/go/csi" |
@@ -86,6 +85,11 @@ func (s *NodeService) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol |
86 | 85 | } |
87 | 86 | klog.V(2).InfoS("Prepared iSCSI target", "portal", portal, "iqn", targetIQN) |
88 | 87 |
|
| 88 | + if err := SaveTargetInfo(stagingPath, target); err != nil { |
| 89 | + klog.ErrorS(err, "Failed to save target info") |
| 90 | + return nil, status.Errorf(codes.Internal, "failed to save target info: %v", err) |
| 91 | + } |
| 92 | + |
89 | 93 | // Check if already logged in |
90 | 94 | klog.V(2).InfoS("Checking iscsi login status") |
91 | 95 | loggedIn, err := s.iscsiManager.IsLoggedIn(ctx, target) |
@@ -158,37 +162,33 @@ func (s *NodeService) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag |
158 | 162 |
|
159 | 163 | stagingPath := req.GetStagingTargetPath() |
160 | 164 |
|
161 | | - // Check if staging path is mounted |
162 | 165 | mounted, err := s.mountManager.IsMounted(stagingPath) |
163 | 166 | if err != nil { |
164 | | - return nil, status.Errorf(codes.Internal, "failed to check if staging path is mounted: %v", err) |
| 167 | + return nil, status.Errorf(codes.Internal, "failed to check mount: %v", err) |
165 | 168 | } |
166 | 169 |
|
167 | 170 | if mounted { |
168 | | - // Get mount info to determine device |
169 | | - mountInfo, err := s.mountManager.GetMountInfo(stagingPath) |
170 | | - if err != nil { |
171 | | - return nil, status.Errorf(codes.Internal, "failed to get mount info: %v", err) |
172 | | - } |
173 | | - |
174 | | - // Unmount the staging path |
175 | | - klog.V(1).InfoS("Unmounting staging path", "staging_path", stagingPath) |
| 171 | + klog.V(2).InfoS("Unmounting staging path", "staging_path", stagingPath) |
176 | 172 | if err := s.mountManager.Unmount(ctx, stagingPath); err != nil { |
177 | 173 | return nil, status.Errorf(codes.Internal, "failed to unmount staging path: %v", err) |
178 | 174 | } |
| 175 | + } |
179 | 176 |
|
180 | | - // Try to logout from iSCSI target |
181 | | - if strings.Contains(mountInfo.Device, "/dev/") { |
182 | | - klog.V(1).InfoS("Device unmounted", "device", mountInfo.Device) |
| 177 | + // Load target info and cleanup iSCSI |
| 178 | + target, err := LoadTargetInfo(stagingPath) |
| 179 | + if err == nil { |
| 180 | + if err := s.iscsiManager.CleanupTarget(ctx, target); err != nil { |
| 181 | + return nil, status.Errorf(codes.Internal, "iscsi cleanup failed: %v", err) |
183 | 182 | } |
184 | 183 | } |
185 | 184 |
|
186 | | - // Remove staging directory |
| 185 | + _ = DeleteTargetInfo(stagingPath) |
| 186 | + |
187 | 187 | if err := os.RemoveAll(stagingPath); err != nil { |
188 | | - klog.ErrorS(err, "Failed to remove staging directory") |
| 188 | + klog.ErrorS(err, "Failed to remove staging directory", "path", stagingPath) |
189 | 189 | } |
190 | 190 |
|
191 | | - klog.InfoS("Volume unstaged successfully", "volume_id", req.GetVolumeId()) |
| 191 | + klog.V(1).InfoS("Volume unstaged successfully", "volume_id", req.GetVolumeId()) |
192 | 192 | return &csi.NodeUnstageVolumeResponse{}, nil |
193 | 193 | } |
194 | 194 |
|
|
0 commit comments