tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Anonymous vnodes?



> Date: Mon, 26 Jun 2023 18:13:17 -0400
> From: Theodore Preduta <theo%pta.gg@localhost>
> 
> Is it possible to create a vnode for a regular file in a file system
> without linking the vnode to any directory, so that it disappears when
> all open file descriptors to it are closed?  (As far as I can tell, this
> isn't possible with any of the vn_* or VOP_* functions?)
> 
> If this idea is indeed not possible, should/could I implement something
> like this?  (If so, how?)
> 
> For context, I'm currently working on implementing memfd_create(2), and
> thought this might be a shortcut.  Otherwise, I'll have to implement it
> in terms of uvm operations (which is fine, just more work).

For a syscall, you should implement it in terms of uvm anonymous
objects:

- memfd_create: fd_allocfile, uao_create
- .fo_close: uao_detach
- .fo_read/write: ubc_uiomove
  (tricky bit: if the offset pointer is &fp->f_offset, you must
  acquire and release fp->f_lock around it)
- .fo_mmap: just take a reference and return the object

Should be easy, and similar to what kern_ksyms.c already does.  No
need for vnodes to be involved at all.


Home | Main Index | Thread Index | Old Index