Skip to content
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

CA-402814: rationalise canonicalisation of device path #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MarkSymsCtx
Copy link
Contributor

Rationalise how the dev path is canonicalized to the /sys/ path using realpath and basename.

The if was redundant as the first line of the method prepends /dev/ if it missing.

Signed-off-by: Mark Syms <mark.syms@cloud.com>
@@ -0,0 +1 @@
.idea
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

@@ -289,9 +289,9 @@ def getDiskBlockSize(dev):
dev = '/dev/' + dev
if isDeviceMapperNode(dev):
return getDiskBlockSize(getDeviceSlaves(dev)[0])
if dev.startswith("/dev/"):
dev = re.match("/dev/(.*)", dev).group(1)
dev = dev.replace("/", "!")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What specifically was wrong with the original code? The same pattern is used in several places in the installer (e.g. in getDiskDeviceSize() above) so if it is buggy then it should be fixed everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well for starters injecting ! into a path is doomed to fail and using regexes instead of os primitives is rather reinventing the wheel.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently there are/were some devices having path separators in their name. And apparently the ! was the /sys path encoding for these devices. os primitives and regexes are doing very different things, some are resolving symlinks converting to physical paths, the others are transforming the paths using just their names.

But @rosslagerwall point still remains, the same code is spread in different places so if one is broken why the others are fine?

I think adding realpath call before instead of replacing should work for both cases (your /dev/by-id/... and the /dev/XXX/YYY)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And probably an exists check as well

Comment on lines +293 to +294
realpath = os.path.realpath(dev)
dev = os.path.basename(realpath)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the code removing /dev/ was redundant giving previous lines, however this not explain this change. The same code you are removing and change is present on the previous function. I think this code is dealing with devices having path separator in them. How your code is dealing with them? It looks like you are removing the support of such devices instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, by using realpath to reduce that down to the actual device rather than the symlink, which should not have path separators in its name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some device name have path separators in their names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants