Add support for scsi#205
Conversation
jodh-intel
left a comment
There was a problem hiding this comment.
Hi @amshinde - thanks for raising. I've added a few comments.
Please could you add some tests for these changes as well?
syscall.go
Outdated
| for _, file := range files { | ||
| host := file.Name() | ||
| scanPath := filepath.Join(scsiHostPath, host, "scan") | ||
| if err := ioutil.WriteFile(scanPath, scanData, 0666); err != nil { |
There was a problem hiding this comment.
Yes, it should be 0200. Fixed.
syscall.go
Outdated
| // but we do need to rescan SCSI bus for this. | ||
| func findSCSIDisk(scsiAddr string) (string, error) { | ||
| // Here in "0:0", the first number is the SCSI host number, while the second number is always 0. | ||
| scsiPath := fmt.Sprintf("/sys/class/scsi_disk/0:0:%s/device/block", scsiAddr) |
There was a problem hiding this comment.
This path prefix is also used in waitForBlockDevice(). Can you make it a file-global var as that will avoid the duplication and hard-coding, but also allow the value to be changed for testing.
There was a problem hiding this comment.
Done. Have added tests as well.
| } | ||
|
|
||
| if fsmap.SCSIAddr != "" { | ||
| source, err = getSCSIDisk(fsmap.SCSIAddr) |
There was a problem hiding this comment.
-
This is resetting
sourceso is it worth adding an extra check to see ifsource != ""here? Or is it guaranteed that ifSCSIAddris set thatSourceis irrelevant?Could you maybe add some comments to the
Fsmaptype to explain this? -
Does this check need to come before the
AbsolutePathcheck above as currently that code is being executed for no reason if we're using a SCSI device?
There was a problem hiding this comment.
I have added in comments.
syscall.go
Outdated
| if _, err := os.Stat(devicePath); err == nil { | ||
| if isSCSIAddr { | ||
| // Here in "0:0", the first number is the SCSI host number, while the second number is always 0. | ||
| scsiPrefix := "/sys/class/scsi_disk/0:0" |
There was a problem hiding this comment.
Can you make this path prefix a file-global var to allow it to be re-used (and changed for testing)?
syscall.go
Outdated
| // Here in "0:0", the first number is the SCSI host number, while the second number is always 0. | ||
| scsiPrefix := "/sys/class/scsi_disk/0:0" | ||
|
|
||
| path := scsiPrefix + deviceName + "/device/block" |
syscall.go
Outdated
| if _, err := os.Stat(path); err == nil { | ||
| return nil | ||
| } | ||
| } else if _, err := os.Stat(devicePath); err == nil { |
There was a problem hiding this comment.
I think it would be clearer if you moved the devicePath variable down to here and removed the else if:
if isSCSIAddr {
:
}
devicePath := filepath.Join(devPath, deviceName)
if _, err := os.Stat(devicePath); err == nil {
return nil
}
syscall.go
Outdated
| if d.Action() == "add" && filepath.Base(d.Devpath()) == deviceName { | ||
|
|
||
| if isSCSIAddr && d.Action() == "add" && strings.Contains(d.Devpath(), deviceName) { | ||
| fieldLogger.Info("Hotplug event received") |
There was a problem hiding this comment.
Maybe "SCSI hotplug event received"?
syscall.go
Outdated
| return nil | ||
| } | ||
|
|
||
| // findSCSIDisk finds the SCSI disk name associated with the given SCSI address |
There was a problem hiding this comment.
Nit: Missing period at end of sentence.
syscall.go
Outdated
| return "", err | ||
| } | ||
|
|
||
| if len(files) > 1 { |
There was a problem hiding this comment.
There is an implicit assumption that a single file was read, so how about the following:
l := len(files)
if l == 0 || l > 1 {
...
}
agent.go
Outdated
| } | ||
|
|
||
| absoluteRootFs, err := mountContainerRootFs(payload.ID, payload.Image, payload.RootFs, payload.FsType) | ||
| absoluteRootFs, err := mountContainerRootFs(payload.ID, payload.Image, payload.RootFs, payload.FsType, payload.SCSIAddr) |
There was a problem hiding this comment.
We should pass the payload to this function, instead of extending its number of parameters, all being attributes of the same structure.
There was a problem hiding this comment.
I had done this to avoid introducing hyperstart specific structures in syscall.go.
There was a problem hiding this comment.
There is no harm doing so. syscall.go is part of the agent, which makes it tied to hyperstart. I don't think this is an issue to pass an hyperstart structure to this function, and this would simplify things as I mentioned.
There was a problem hiding this comment.
I was just trying to avoid introducing any hyperstart structures here, as this is more like an utils package and is a good contender for moving into its own util package, but that is for the future.
I can simplify this for now.
There was a problem hiding this comment.
I have pushed changes for this.
| SystemMountsInfo SystemMountsInfo `json:"systemMountsInfo"` | ||
|
|
||
| // SCSI address in the format SCSI-Id:LUN | ||
| SCSIAddr string `json:"scsiAddr,omitempty"` |
There was a problem hiding this comment.
I am not sure this is the right place for this field. This is very specific to a type of rootfs. Maybe we should define a structure Rootfs so that we can actually include this type of information. WDYT ?
There was a problem hiding this comment.
Yes, this is specific to rootfs, but we have other fields here like Rootfs, FsMap and FsType that are related to rootfs that Iwould be candidates for a combined structure. I would like to do that in a separate PR, as this involves a lot of components.
There was a problem hiding this comment.
Fair enough, but please open an issue to track this down ;)
| } | ||
|
|
||
| func waitForBlockDevice(deviceName string) error { | ||
| func waitForBlockDevice(deviceName string, isSCSIAddr bool) error { |
There was a problem hiding this comment.
You should rename this function into waitForDevice() and pass a more global structure. Once again, this looks very specific to SCSI here.
There was a problem hiding this comment.
I would prefer keeping this as is as we are waiting for a Block device here, the difference being if the device is passed with virtio-scsi or virtio-block, with the flag indicating this.
There was a problem hiding this comment.
Yes I agree this is still a block device, forget this comment.
1ac4d30 to
66f12ab
Compare
syscall.go
Outdated
| var path string | ||
|
|
||
| if isSCSIAddr { | ||
| path = scsiDiskPrefix + deviceName + "/device/block" |
There was a problem hiding this comment.
This would be more consistent (and maybe safer) as:
path = filepath.Join(scsiDiskPrefix + deviceName, "/device/block")
You could also create a variable for the /device/block which is used multiple times.
syscall.go
Outdated
| if d.Action() == "add" && filepath.Base(d.Devpath()) == deviceName { | ||
| fieldLogger.Info("Hotplug event received") | ||
|
|
||
| //if isSCSIAddr && d.Action() == "add" && strings.Contains(d.Devpath(), deviceName) { |
syscall.go
Outdated
| fieldLogger.Info("Hotplug event received") | ||
|
|
||
| //if isSCSIAddr && d.Action() == "add" && strings.Contains(d.Devpath(), deviceName) { | ||
| if isSCSIAddr && d.Action() == "add" && strings.Contains(d.Devpath(), "/0:0:"+deviceName+"/block") { |
There was a problem hiding this comment.
Can you create a global private variable for the 0:0 (and ideally change scsiDiskPrefix to use it too)?
syscall.go
Outdated
|
|
||
| // scanSCSIBus scans SCSI bus for the given SCSI address(SCSI-Id and LUN) | ||
| func scanSCSIBus(scsiAddr string) error { | ||
| if _, err := os.Stat(scsiHostPath); err != nil { |
There was a problem hiding this comment.
This call isn't needed as the ReadDir() below will detect ENOENT itself. Same comment for the Stat() in findSCSIDisk().
syscall.go
Outdated
| // If device node is not found, wait for udev event for the scsi disk, | ||
| // with the format "0:SCSIId:LUN/block" | ||
|
|
||
| //if err := waitForBlockDevice("0:"+scsiAddr+"/block", true); err != nil { |
f946e73 to
be3f50e
Compare
|
@jodh-intel I have pushed changes for your comments. Please have a look. |
Add support for SCSI disks to be passed for container rootfs. If SCSI address is provided, use that to get the SCSI disk name. This eliminates the need to predict the drive name of the block device on the host side. We do need to incur the cost of scanning SCSI bus. Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
Similar to rootfs, add support for SCSI disk to be passed for a volume mount. Fixes clearcontainers#209 Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
be3f50e to
3eacdd5
Compare
|
LGTM |
Add support for SCSI disks to be passed for container rootfs and volumes.
If SCSI address is provided, use that to get the SCSI disk name.
This eliminates the need to predict the drive name of the block
device on the host side. We do need to incur the cost of scanning SCSI bus.