qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] How are the temporary files (-snapshot) created on Linux?
@ 2008-09-12  6:04 EQX
  2008-09-12 10:18 ` Yann E. MORIN
  0 siblings, 1 reply; 5+ messages in thread
From: EQX @ 2008-09-12  6:04 UTC (permalink / raw)
  To: qemu-devel


Hi list

You're doing great work, thanks for that.

The code says the -snapshot temporary files are created here:  
/tmp/vl.*, but they are never visible for users. Using lsof, they have  
a state of 'deleted'. How does this work exactly? What type of file is  
this?

Thanks, Mike

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] How are the temporary files (-snapshot) created on Linux?
  2008-09-12  6:04 [Qemu-devel] How are the temporary files (-snapshot) created on Linux? EQX
@ 2008-09-12 10:18 ` Yann E. MORIN
  2008-09-12 11:24   ` Steve Fosdick
  0 siblings, 1 reply; 5+ messages in thread
From: Yann E. MORIN @ 2008-09-12 10:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: EQX

Hello!

On Friday 12 September 2008 08:04:02 EQX wrote:
> The code says the -snapshot temporary files are created here:  
> /tmp/vl.*, but they are never visible for users. Using lsof, they have  
> a state of 'deleted'. How does this work exactly? What type of file is  
> this?

It's done via some incantation of open(2) followed by unlink(2), something
like:

  int fd;
  fd = open( "/tmp/vl.xxx", O_CREAT|... );
  unlink( "/tmp/vl.xxx" );
  /* Use the file somehow */
  close( fd );

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +0/33 662376056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| --==< ^_^ >==-- `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
`------------------------------^-------^------------------^--------------------'

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] How are the temporary files (-snapshot) created on Linux?
  2008-09-12 10:18 ` Yann E. MORIN
@ 2008-09-12 11:24   ` Steve Fosdick
  2008-09-12 14:52     ` EQX
  2008-09-12 16:57     ` Jamie Lokier
  0 siblings, 2 replies; 5+ messages in thread
From: Steve Fosdick @ 2008-09-12 11:24 UTC (permalink / raw)
  To: qemu-devel

On 12/09/08 11:18:50, Yann E. MORIN wrote:
> Hello!
> 
> On Friday 12 September 2008 08:04:02 EQX wrote:
> > The code says the -snapshot temporary files are created here:  
> > /tmp/vl.*, but they are never visible for users. Using lsof,
> > they have a state of 'deleted'. How does this work exactly?
> > What type of file is this?
> 
> It's done via some incantation of open(2) followed by unlink(2),
> something
> like:
> 
>   int fd;
>   fd = open( "/tmp/vl.xxx", O_CREAT|... );
>   unlink( "/tmp/vl.xxx" );
>   /* Use the file somehow */
>   close( fd );
> 
> Regards,
> Yann E. MORIN.

There is nothing special about the files concerned.  The key to this is 
that, unlike some other operating systems, Linux (like Unix) allows an 
open file to be deleted and has a well defined way to deal with that 
happenning.

When an open file is deleted only the file name is actually deleted.  
The data in the file (and any new data written to the file) are kept 
until the last process to have the file open closes the file whereupon 
the second half of the delete happens, i.e. deallocating the disk 
storage and returning it to the free space.

This mechanism is exploited by a process that opens a file and 
immediately deletes it like the example above for two reasons:

1. It provides a way to guarantee that the file not exist after the 
process concerned has finished even if it finishes abnormally or gets 
killed for some reason.

2. As a security measure.  Once the file name has been deleted there is 
no way for any other process to stumble upon the file and open it.

The second point is negated somewhat by the /proc filesystem.

Regards,
Steve.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] How are the temporary files (-snapshot) created on Linux?
  2008-09-12 11:24   ` Steve Fosdick
@ 2008-09-12 14:52     ` EQX
  2008-09-12 16:57     ` Jamie Lokier
  1 sibling, 0 replies; 5+ messages in thread
From: EQX @ 2008-09-12 14:52 UTC (permalink / raw)
  To: qemu-devel


Thank you for this good explanation!

Mike


Quoting Steve Fosdick <lists@pelvoux.nildram.co.uk>:

> On 12/09/08 11:18:50, Yann E. MORIN wrote:
>> Hello!
>>
>> On Friday 12 September 2008 08:04:02 EQX wrote:
>> > The code says the -snapshot temporary files are created here:
>> > /tmp/vl.*, but they are never visible for users. Using lsof,
>> > they have a state of 'deleted'. How does this work exactly?
>> > What type of file is this?
>>
>> It's done via some incantation of open(2) followed by unlink(2),
>> something
>> like:
>>
>>   int fd;
>>   fd = open( "/tmp/vl.xxx", O_CREAT|... );
>>   unlink( "/tmp/vl.xxx" );
>>   /* Use the file somehow */
>>   close( fd );
>>
>> Regards,
>> Yann E. MORIN.
>
> There is nothing special about the files concerned.  The key to this is
> that, unlike some other operating systems, Linux (like Unix) allows an
> open file to be deleted and has a well defined way to deal with that
> happenning.
>
> When an open file is deleted only the file name is actually deleted.
> The data in the file (and any new data written to the file) are kept
> until the last process to have the file open closes the file whereupon
> the second half of the delete happens, i.e. deallocating the disk
> storage and returning it to the free space.
>
> This mechanism is exploited by a process that opens a file and
> immediately deletes it like the example above for two reasons:
>
> 1. It provides a way to guarantee that the file not exist after the
> process concerned has finished even if it finishes abnormally or gets
> killed for some reason.
>
> 2. As a security measure.  Once the file name has been deleted there is
> no way for any other process to stumble upon the file and open it.
>
> The second point is negated somewhat by the /proc filesystem.
>
> Regards,
> Steve.
>
>
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] How are the temporary files (-snapshot) created on Linux?
  2008-09-12 11:24   ` Steve Fosdick
  2008-09-12 14:52     ` EQX
@ 2008-09-12 16:57     ` Jamie Lokier
  1 sibling, 0 replies; 5+ messages in thread
From: Jamie Lokier @ 2008-09-12 16:57 UTC (permalink / raw)
  To: qemu-devel

Steve Fosdick wrote:
> On 12/09/08 11:18:50, Yann E. MORIN wrote:
> > Hello!
> > 
> > On Friday 12 September 2008 08:04:02 EQX wrote:
> > > The code says the -snapshot temporary files are created here:  
> > > /tmp/vl.*, but they are never visible for users. Using lsof,
> > > they have a state of 'deleted'. How does this work exactly?
> > > What type of file is this?
> > 
> > It's done via some incantation of open(2) followed by unlink(2),
> > something
> > like:
> > 
> >   int fd;
> >   fd = open( "/tmp/vl.xxx", O_CREAT|... );
> >   unlink( "/tmp/vl.xxx" );
> >   /* Use the file somehow */
> >   close( fd );
> > 
> > Regards,
> > Yann E. MORIN.
> 
> There is nothing special about the files concerned.  The key to this is 
> that, unlike some other operating systems, Linux (like Unix) allows an 
> open file to be deleted and has a well defined way to deal with that 
> happenning.
> 
> When an open file is deleted only the file name is actually deleted.  
> The data in the file (and any new data written to the file) are kept 
> until the last process to have the file open closes the file whereupon 
> the second half of the delete happens, i.e. deallocating the disk 
> storage and returning it to the free space.
> 
> This mechanism is exploited by a process that opens a file and 
> immediately deletes it like the example above for two reasons:
> 
> 1. It provides a way to guarantee that the file not exist after the 
> process concerned has finished even if it finishes abnormally or gets 
> killed for some reason.
> 
> 2. As a security measure.  Once the file name has been deleted there is 
> no way for any other process to stumble upon the file and open it.
> 
> The second point is negated somewhat by the /proc filesystem.

Also both points are negated for a brief time window by the fact you
have to have the file exist momentarily - there's no O_UNLINK flag to open.

-- Jamie

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-09-12 16:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-12  6:04 [Qemu-devel] How are the temporary files (-snapshot) created on Linux? EQX
2008-09-12 10:18 ` Yann E. MORIN
2008-09-12 11:24   ` Steve Fosdick
2008-09-12 14:52     ` EQX
2008-09-12 16:57     ` Jamie Lokier

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 NNTP newsgroup(s).