All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Devendra Tewari" <devendra.tewari@gmail.com>
To: Khem Raj <raj.khem@gmail.com>
Cc: Richard Purdie <richard.purdie@linuxfoundation.org>,
	Andre McCurdy <armccurdy@gmail.com>,
	OE Core mailing list <openembedded-core@lists.openembedded.org>
Subject: Re: [OE-core] [PATCH] Use shutil.move when os.rename fails
Date: Wed, 21 Apr 2021 11:43:18 -0300	[thread overview]
Message-ID: <F23C2F80-7F48-4384-A946-34152D4FCBDD@gmail.com> (raw)
In-Reply-To: <CAMKF1sqYpfoFeThNAJDyhH5KZgpbBS2TRj8CSmiiyK_edqBkJw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5844 bytes --]

I created an image for Raspberry Pi Zero W from code at https://github.com/tewarid/docker-meta-raspberrypi/tree/sstate <https://github.com/tewarid/docker-meta-raspberrypi/tree/sstate>, using Docker for macOS, and on Ubuntu 20.04-LTS, and wrote it out to an SDCard using bmaptool. Booted and checked that busybox symlinks in rootfs look all right.

> Em 21 de abr. de 2021, à(s) 02:22, Khem Raj <raj.khem@gmail.com> escreveu:
> 
> None of my images are bootable when this patch is applied, because
> symlinks that busybox should provide arent created in the image. This
> patch should be looked into a bit further,  how was it tested ?
> 
>> On Mon, Apr 19, 2021 at 11:43 AM Devendra Tewari
>> <devendra.tewari@gmail.com> wrote:
>> 
>> 
>> 
>>>> On 30 Mar 2021, at 08:55, Devendra Tewari <devendra.tewari@gmail.com> wrote:
>>> 
>>> I understand that parallel tasks can result in such issues, but would expect some kind of dependency graph that would prevent them from happening. I wish I had more time to understand the issue fully.
>>> 
>>> Here’s the last version of my patch that still uses os.rename, and on error uses shutil.move, with the reasoning explained in the commit message. There are tons of os.rename in code elsewhere, and I’ve encountered similar issues when doing incremental builds, but I’ll leave fixing them to those with more time at hand. Cheers.
>> 
>> Here’s a patch that catches error with all os.rename in the code, and retries with shutil.move when that happens.
>> 
>> 
>>> 
>>> From aeba1f9728f69cdf2ce4ba285be86761d8024f9d Mon Sep 17 00:00:00 2001
>>> From: Devendra Tewari <devendra.tewari@gmail.com>
>>> Date: Tue, 30 Mar 2021 08:27:40 -0300
>>> Subject: [PATCH] Use shutil.move when os.rename fails
>>> 
>>> Incremental build in Docker fails with
>>> 
>>> OSError: [Errno 18] Invalid cross-device link
>>> 
>>> When source and destination are on different overlay filesystems.
>>> 
>>> This change handles error with os.rename and retries with shutil.move.
>>> The reason os.rename is still used is because shutil.move is too slow
>>> for speed sensitive sections of code.
>>> ---
>>> meta/classes/sstate.bbclass | 22 ++++++++++++++++++----
>>> 1 file changed, 18 insertions(+), 4 deletions(-)
>>> 
>>> diff --git a/meta/classes/sstate.bbclass b/meta/classes/sstate.bbclass
>>> index f579168162..301dfc27db 100644
>>> --- a/meta/classes/sstate.bbclass
>>> +++ b/meta/classes/sstate.bbclass
>>> @@ -384,6 +384,7 @@ def sstate_installpkg(ss, d):
>>> def sstate_installpkgdir(ss, d):
>>>   import oe.path
>>>   import subprocess
>>> +    import shutil
>>> 
>>>   sstateinst = d.getVar("SSTATE_INSTDIR")
>>>   d.setVar('SSTATE_FIXMEDIR', ss['fixmedir'])
>>> @@ -401,7 +402,10 @@ def sstate_installpkgdir(ss, d):
>>> 
>>>   for state in ss['dirs']:
>>>       prepdir(state[1])
>>> -        os.rename(sstateinst + state[0], state[1])
>>> +        try:
>>> +            os.rename(sstateinst + state[0], state[1])
>>> +        except OSError:
>>> +            shutil.move(sstateinst + state[0], state[1])
>>>   sstate_install(ss, d)
>>> 
>>>   for plain in ss['plaindirs']:
>>> @@ -413,7 +417,10 @@ def sstate_installpkgdir(ss, d):
>>>       dest = plain
>>>       bb.utils.mkdirhier(src)
>>>       prepdir(dest)
>>> -        os.rename(src, dest)
>>> +        try:
>>> +            os.rename(src, dest)
>>> +        except OSError:
>>> +            shutil.move(src, dest)
>>> 
>>>   return True
>>> 
>>> @@ -638,6 +645,7 @@ python sstate_hardcode_path () {
>>> 
>>> def sstate_package(ss, d):
>>>   import oe.path
>>> +    import shutil
>>> 
>>>   tmpdir = d.getVar('TMPDIR')
>>> 
>>> @@ -664,7 +672,10 @@ def sstate_package(ss, d):
>>>                   continue
>>>               bb.error("sstate found an absolute path symlink %s pointing at %s. Please replace this with a relative link." % (srcpath, link))
>>>       bb.debug(2, "Preparing tree %s for packaging at %s" % (state[1], sstatebuild + state[0]))
>>> -        os.rename(state[1], sstatebuild + state[0])
>>> +        try:
>>> +            os.rename(state[1], sstatebuild + state[0])
>>> +        except OSError:
>>> +            shutil.move(state[1], sstatebuild + state[0])
>>> 
>>>   workdir = d.getVar('WORKDIR')
>>>   sharedworkdir = os.path.join(d.getVar('TMPDIR'), "work-shared")
>>> @@ -674,7 +685,10 @@ def sstate_package(ss, d):
>>>           pdir = plain.replace(sharedworkdir, sstatebuild)
>>>       bb.utils.mkdirhier(plain)
>>>       bb.utils.mkdirhier(pdir)
>>> -        os.rename(plain, pdir)
>>> +        try:
>>> +            os.rename(plain, pdir)
>>> +        except OSError:
>>> +            shutil.move(plain, pdir)
>>> 
>>>   d.setVar('SSTATE_BUILDDIR', sstatebuild)
>>>   d.setVar('SSTATE_INSTDIR', sstatebuild)
>>> --
>>> 2.29.2
>>> 
>>> 
>>>> On 30 Mar 2021, at 08:10, Richard Purdie <richard.purdie@linuxfoundation.org> wrote:
>>>> 
>>>> On Mon, 2021-03-29 at 16:00 -0700, Andre McCurdy wrote:
>>>>> On Mon, Mar 29, 2021 at 3:45 PM Devendra Tewari
>>>>> <devendra.tewari@gmail.com> wrote:
>>>>>> 
>>>>>> Thanks! My bad. The example I looked up in Python docs had a break and I just realized it was a looping example.
>>>>>> 
>>>>>> Here’s the updated patch (or should I submit it again via git send-email?)
>>>>> 
>>>>> It would be better to use shutil.move unconditionally in all cases,
>>>>> rather than have a separate shutil.move code path which only gets
>>>>> tested by people doing incremental builds in docker.
>>>> 
>>>> This is a speed sensitive section of code and shutil has traditionally proved
>>>> to be slow so I disagree with that, rename is very much preferred here where
>>>> we can.
>>>> 
>>>> Cheers,
>>>> 
>>>> Richard
>>>> 
>>>> 
>>> 
>> 
>> 
>> 
>> 

[-- Attachment #2: Type: text/html, Size: 9287 bytes --]

  reply	other threads:[~2021-04-21 14:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-29 15:14 [PATCH] Use shutil.move when os.rename fails devendra.tewari
2021-03-29 15:21 ` [OE-core] " Bruce Ashfield
2021-03-29 15:23   ` Konrad Weihmann
2021-03-29 15:35     ` Devendra Tewari
2021-03-29 15:37       ` Devendra Tewari
2021-03-30 21:59         ` Denys Dmytriyenko
2021-03-30 22:38           ` Devendra Tewari
2021-04-01 19:14             ` Devendra Tewari
2021-03-29 20:38 ` Richard Purdie
2021-03-29 22:45   ` Devendra Tewari
2021-03-29 23:00     ` Andre McCurdy
2021-03-29 23:07       ` Devendra Tewari
2021-03-29 23:10         ` Andre McCurdy
2021-03-29 23:13           ` Devendra Tewari
2021-03-30 10:16             ` Devendra Tewari
2021-03-30 11:10       ` Richard Purdie
2021-03-30 11:55         ` Devendra Tewari
2021-04-19 18:43           ` Devendra Tewari
2021-04-21  5:21             ` Khem Raj
2021-04-21 14:43               ` Devendra Tewari [this message]
2021-04-21 15:15                 ` Khem Raj
2021-04-21 18:10                 ` Richard Purdie
2021-04-21 19:15                   ` Devendra Tewari
2021-04-21 19:21                     ` Richard Purdie
2021-04-21 21:08                       ` Devendra Tewari
2021-04-27 11:57                         ` Devendra Tewari
2021-04-27 14:59                           ` Devendra Tewari
2021-04-27 22:39                             ` Richard Purdie
2021-04-27 22:44                               ` Devendra Tewari
2021-04-27 22:53                                 ` Devendra Tewari
2021-04-28 10:00                                   ` Devendra Tewari
2021-04-28 21:42                                     ` Richard Purdie
2021-04-28 23:02                                       ` Devendra Tewari
     [not found]                                       ` <90B42906-44DE-4D61-8210-669DC25BBD3F@gmail.com>
2022-08-22 12:25                                         ` Devendra Tewari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F23C2F80-7F48-4384-A946-34152D4FCBDD@gmail.com \
    --to=devendra.tewari@gmail.com \
    --cc=armccurdy@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=raj.khem@gmail.com \
    --cc=richard.purdie@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.