unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: bokr@bokr.com
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: Maxime Devos <maximedevos@telenet.be>,
	Arun Isaac <arunisaac@systemreboot.net>,
	Guix Devel <guix-devel@gnu.org>
Subject: Re: Move switch-symlinks to (guix build utils)
Date: Sat, 4 Jun 2022 01:55:05 +0200	[thread overview]
Message-ID: <20220603235505.GA2742@LionPure> (raw)
In-Reply-To: <87h751ily8.fsf@gnu.org>

Hi,

I am not expert on kernel link internals, but if
you need/prefer atomic change to a specific link,
does my log [1] below suggest a way?

On +2022-06-03 21:30:39 +0200, Ludovic Courtès wrote:
> Hi,
> 
> Maxime Devos <maximedevos@telenet.be> skribis:
> 
> >, Maybe replace
> >
> >    (symlink target pivot)
> >
> > by (symlink/remove-old target pivot)
> >
> > where
> >
> > (define (symlink/remove-old target link)
> >   "Make a symbolic link named LINK pointing to TARGET.
> > If LINK already exists, it will be removed first.
> > This is not an atomic operation."
> >   (catch 'system-error
> >     (lambda ()
> >       (symlink target link))
> >     (lambda stuff
> >       (if (= (system-error-errno stuff) EEXIST)
> >           (begin
> >             ;; remove old link and retry
> >             (delete-file link)
> >             (symlink/remove-old link target))
> >           (apply throw stuff)))))
> 
> Alright, SGTM (this procedure would be kept private).
> 
> So Arun, the floor is yours!  :-)
> 
> Ludo’.
>

[0]: (some "<--= note" notes edited in)
BTW: notice that Size: is number of chars in TARGET name, not the LINK name
--8<---------------cut here---------------start------------->8---
$ ln -sT TARGET LINK
$ stat LINK
  File: LINK -> TARGET
  Size: 6               Blocks: 0          IO Block: 4096   symbolic link
Device: fe00h/65024d    Inode: 19401553    Links: 1   # <--= note inode number: mv will not change it
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/    bokr)   Gid: ( 1000/    bokr)
Access: 2022-06-04 00:57:47.680832044 +0200
Modify: 2022-06-04 00:57:47.680832044 +0200
Change: 2022-06-04 00:57:47.680832044 +0200
 Birth: -
$ mv -v LINK WAS-LINK
renamed 'LINK' -> 'WAS-LINK'
$ stat WAS-LINK
  File: WAS-LINK -> TARGET
  Size: 6               Blocks: 0          IO Block: 4096   symbolic link # <--= TARGET is still 6 chars :)
Device: fe00h/65024d    Inode: 19401553    Links: 1    # <--= note inode number: did not change with mv
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/    bokr)   Gid: ( 1000/    bokr)
Access: 2022-06-04 00:57:47.680832044 +0200
Modify: 2022-06-04 00:57:47.680832044 +0200
Change: 2022-06-04 00:58:33.617240104 +0200
 Birth: -
$ ln -sT NEW-TARGET LINK
$ stat LINK 
  File: LINK -> NEW-TARGET
  Size: 10              Blocks: 0          IO Block: 4096   symbolic link # <--= NEW-TARGET is 10 chars :)
Device: fe00h/65024d    Inode: 19401638    Links: 1    <--= note inode number: new for new use of LINK name
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/    bokr)   Gid: ( 1000/    bokr)
Access: 2022-06-04 01:00:10.630121441 +0200
Modify: 2022-06-04 01:00:10.630121441 +0200
Change: 2022-06-04 01:00:10.630121441 +0200
 Birth: -
$ rm -v WAS-LINK      <--= note no OS objection to removing renamed old LINK
removed 'WAS-LINK'
$ stat *LINK*
  File: LINK -> NEW-TARGET
  Size: 10              Blocks: 0          IO Block: 4096   symbolic link
Device: fe00h/65024d    Inode: 19401638    Links: 1
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/    bokr)   Gid: ( 1000/    bokr)
Access: 2022-06-04 01:00:10.630121441 +0200
Modify: 2022-06-04 01:00:10.630121441 +0200
Change: 2022-06-04 01:00:10.630121441 +0200
 Birth: -
$ 
--8<---------------cut here---------------end--------------->8---

I'm guessing the inode rewrite involved in mv -v LINK WAS-LINK should be atomic?
Maybe some kernels have to struggle without good hardware support, but still atomic?

Maybe a kernel insider will chime in?
HTH some way.
--
Regards,
Bengt Richter


  reply	other threads:[~2022-06-03 23:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01  7:34 Move switch-symlinks to (guix build utils) Arun Isaac
2022-06-01 12:09 ` Maxime Devos
2022-06-02 15:06   ` Arun Isaac
2022-06-02 15:13     ` Maxime Devos
2022-06-03 16:38       ` Ludovic Courtès
2022-06-03 17:09         ` Maxime Devos
2022-06-03 19:30           ` Ludovic Courtès
2022-06-03 19:30           ` Ludovic Courtès
2022-06-03 23:55             ` bokr [this message]
2022-06-04 10:17               ` Maxime Devos
2022-06-06 11:27           ` Arun Isaac
2022-06-06 12:20             ` Maxime Devos
2022-06-08 20:12               ` Arun Isaac

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

  List information: https://guix.gnu.org/

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

  git send-email \
    --in-reply-to=20220603235505.GA2742@LionPure \
    --to=bokr@bokr.com \
    --cc=arunisaac@systemreboot.net \
    --cc=guix-devel@gnu.org \
    --cc=ludo@gnu.org \
    --cc=maximedevos@telenet.be \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).