Possible to speedup chownr?

Bug #1898605 reported by Ponnuvel Palaniyappan
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ceph OSD Charm
Fix Released
Undecided
Ponnuvel Palaniyappan
Charm Helpers
Fix Committed
Undecided
Ponnuvel Palaniyappan

Bug Description

I wonder if `chownr` function (recursive chown) can be improved.

It calls `os.path.lexists` and `os.path.exists` for *every* file. The relevant source code from https://github.com/juju/charm-helpers/blob/master/charmhelpers/core/host.py#L927:

    for root, dirs, files in os.walk(path, followlinks=follow_links):
        for name in dirs + files:
            full = os.path.join(root, name)
            broken_symlink = os.path.lexists(full) and not os.path.exists(full)
            if not broken_symlink:
                chown(full, uid, gid)

I think the purpose of the extra check (not broken symlink) is to avoid calling chown on broken symlinks. Would rewriting this part to:

    for root, dirs, files in os.walk(path, followlinks=follow_links):
        for name in dirs + files:
            full = os.path.join(root, name)
            try:
                chown(full, uid, gid)
            except FileNotFoundError:
                pass

do the equivalent functionality? This would avoid nearly 2 system calls for every file.

Ordinarily, these "extra" system calls wouldn't be an issue for a directory with few files. But in case of ceph-osd charm where there can be a massive number of files, this is noticeable (few mins to hours - depending on the number of files).

Tags: seg
Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :
tags: added: seg
Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :

Closed the previous PR noted in #1 and new one is at https://github.com/juju/charm-helpers/pull/527 after addressing review comments.

Changed in charm-helpers:
status: New → In Progress
assignee: nobody → Ponnuvel Palaniyappan (pponnuvel)
Changed in charm-ceph-osd:
assignee: nobody → Ponnuvel Palaniyappan (pponnuvel)
Changed in charm-helpers:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on charm-ceph-osd (master)

Change abandoned by Ponnuvel Palaniyappan (<email address hidden>) on branch: master
Review: https://review.opendev.org/759956

Changed in charm-ceph-osd:
status: In Progress → Fix Committed
Revision history for this message
Ponnuvel Palaniyappan (pponnuvel) wrote :
David Ames (thedac)
Changed in charm-ceph-osd:
milestone: none → 21.01
David Ames (thedac)
Changed in charm-ceph-osd:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.