preserve inode when copying?

25 views
Skip to first unread message

Anne Bennett

unread,
Apr 7, 2018, 9:35:54 AM4/7/18
to help-c...@googlegroups.com

I have some situations where a single file is bind-mounted (in a chroot).
With cfengine2's "copy" command, when the file's contents are replaced,
this results in the inode number changing, which breaks the bind mount.

I can't find an option in either cfengine2 or cfengine3's documentation
to specify that the copy should overwrite the file in place to
avoid changing the inode.

Any advice?

--
Anne.

Nick Anderson

unread,
Apr 7, 2018, 10:27:27 AM4/7/18
to help-cfengine
I don't think cfengine will write directly to the promised file. It should always write to .cfnew and then move into place.


Anne Bennett

unread,
Apr 7, 2018, 10:36:59 AM4/7/18
to Nick Anderson, help-cfengine
On Sat, Apr 7, 2018 at 10:27 AM, Nick Anderson <ni...@cmdln.org> wrote
> I don't think cfengine will write directly to the promised file. It should always
> write to .cfnew and then move into place.

It would be helpful to have an option to write directly. I can see why in
most instances it would be safer to write to a temporary file and then
unlink/link/unlink to put the new material in place, but the above way of
doing things makes it impossible to manage a file with cfengine if it is
to be bind-mounted. :-(

Can you consider this a feature request, please? That is, an option
to "copy" to make it overwrite the data, keeping the same inode.

--
Anne.

Aleksey Tsalolikhin

unread,
Apr 7, 2018, 11:13:31 AM4/7/18
to Anne Bennett, Nick Anderson, help-cfengine
On Sat, Apr 7, 2018, 10:36 AM Anne Bennett <anne.porcupine.bennett@gmail.com> wrote:
It would be helpful to have an option to write directly.  I can see why in
most instances it would be safer to write to a temporary file and then
unlink/link/unlink to put the new material in place, but the above way of
doing things makes it impossible to manage a file with cfengine if it is
to be bind-mounted.  :-(

Can you consider this a feature request, please?  That is, an option
to "copy" to make it overwrite the data, keeping the same inode.

Hi Anne! Good to see you on here. It was nice to meet you at LISA '17.

Nick, I've run into a related issue while testing our CFEngine policy in containers. Certain files (like /etc/hosts) are bind-mounted from the host so CFEngine's attempt to move them were making noise (errors).

For example:

root@ubuntu:~# docker run -ti alpine sh
.../ # df 
Filesystem           1K-blocks      Used Available Use% Mounted on
...
/dev/sda1             32895856  12309868  18891936  39% /etc/resolv.conf
/dev/sda1             32895856  12309868  18891936  39% /etc/hostname
/dev/sda1             32895856  12309868  18891936  39% /etc/hosts
...
/ # mv /etc/hosts /etc/hosts.old
mv: can't rename '/etc/hosts': Resource busy
/ # 

However, if I edit the file without changing the inode (e.g. with vim or sed), I can change the file.

It would be nice to be able to test my "files" promises in container environments, since that's the modern way to test software.

I am not sure what the solution is, but I just wanted to add my perspective as I also have run into this issue (or a closely related one).

Maybe an attribute that would tell CFEngine yes, I accept the risks of editing the file in place as opposed to installing the new version atomically with rename, please do that for me?

Thanks!
Aleksey

Nick Anderson

unread,
Apr 7, 2018, 3:05:29 PM4/7/18
to Anne Bennett, Nick Anderson, help-cfengine
I opened an issue to track the request:
https://tracker.mender.io/browse/CFE-2796

Pull requests to implement support are most welcome.

Aleksey Tsalolikhin

unread,
Apr 7, 2018, 3:11:27 PM4/7/18
to Nick Anderson, Anne Bennett, help-cfengine
Gosh, Nick, that's going above and beyond, thank you, mate!!  

And you should join us in Nashville this year for LISA '18 if you can.  =)  It's been too long.

Yours fondly,
Aleksey

-- 
Achieve real learning.  Email trai...@verticalsysadmin.com.

On Sat, Apr 7, 2018 at 3:05 PM, 'Nick Anderson' via help-cfengine <help-c...@googlegroups.com> wrote:
I opened an issue to track the request:
https://tracker.mender.io/browse/CFE-2796

Pull requests to implement support are most welcome.

On Sat, Apr 7, 2018 at 9:36 AM, Anne Bennett <anne.porcupine.bennett@gmail.com> wrote:
On Sat, Apr 7, 2018 at 10:27 AM, Nick Anderson <ni...@cmdln.org> wrote
> I don't think cfengine will write directly to the promised file. It should always
> write to .cfnew and then move into place.

It would be helpful to have an option to write directly.  I can see why in
most instances it would be safer to write to a temporary file and then
unlink/link/unlink to put the new material in place, but the above way of
doing things makes it impossible to manage a file with cfengine if it is
to be bind-mounted.  :-(

Can you consider this a feature request, please?  That is, an option
to "copy" to make it overwrite the data, keeping the same inode.

--
Anne.

--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengine+unsubscribe@googlegroups.com.
To post to this group, send email to help-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/help-cfengine.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages