server: Reuse existing file descriptor objects for duplicate file mappings.
This commit is contained in:
parent
55bfd2ef0d
commit
200f8d958f
14
server/fd.c
14
server/fd.c
|
@ -1670,6 +1670,20 @@ failed:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* find an existing fd object that can be reused for a mapping */
|
||||||
|
struct fd *get_fd_object_for_mapping( struct fd *fd, unsigned int access, unsigned int sharing )
|
||||||
|
{
|
||||||
|
struct fd *fd_ptr;
|
||||||
|
|
||||||
|
if (!fd->inode) return NULL;
|
||||||
|
|
||||||
|
LIST_FOR_EACH_ENTRY( fd_ptr, &fd->inode->open, struct fd, inode_entry )
|
||||||
|
if (fd_ptr->access == access && fd_ptr->sharing == sharing)
|
||||||
|
return (struct fd *)grab_object( fd_ptr );
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* set the status to return when the fd has no associated unix fd */
|
/* set the status to return when the fd has no associated unix fd */
|
||||||
void set_no_fd_status( struct fd *fd, unsigned int status )
|
void set_no_fd_status( struct fd *fd, unsigned int status )
|
||||||
{
|
{
|
||||||
|
|
|
@ -61,6 +61,7 @@ extern struct fd *create_anonymous_fd( const struct fd_ops *fd_user_ops,
|
||||||
int unix_fd, struct object *user, unsigned int options );
|
int unix_fd, struct object *user, unsigned int options );
|
||||||
extern struct fd *dup_fd_object( struct fd *orig, unsigned int access, unsigned int sharing,
|
extern struct fd *dup_fd_object( struct fd *orig, unsigned int access, unsigned int sharing,
|
||||||
unsigned int options );
|
unsigned int options );
|
||||||
|
extern struct fd *get_fd_object_for_mapping( struct fd *fd, unsigned int access, unsigned int sharing );
|
||||||
extern void *get_fd_user( struct fd *fd );
|
extern void *get_fd_user( struct fd *fd );
|
||||||
extern void set_fd_user( struct fd *fd, const struct fd_ops *ops, struct object *user );
|
extern void set_fd_user( struct fd *fd, const struct fd_ops *ops, struct object *user );
|
||||||
extern unsigned int get_fd_options( struct fd *fd );
|
extern unsigned int get_fd_options( struct fd *fd );
|
||||||
|
|
|
@ -496,6 +496,7 @@ static struct object *create_mapping( struct directory *root, const struct unico
|
||||||
|
|
||||||
if (handle)
|
if (handle)
|
||||||
{
|
{
|
||||||
|
const unsigned int sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
||||||
unsigned int mapping_access = FILE_MAPPING_ACCESS;
|
unsigned int mapping_access = FILE_MAPPING_ACCESS;
|
||||||
|
|
||||||
if (!(protect & VPROT_COMMITTED))
|
if (!(protect & VPROT_COMMITTED))
|
||||||
|
@ -509,14 +510,16 @@ static struct object *create_mapping( struct directory *root, const struct unico
|
||||||
/* file sharing rules for mappings are different so we use magic the access rights */
|
/* file sharing rules for mappings are different so we use magic the access rights */
|
||||||
if (protect & VPROT_IMAGE) mapping_access |= FILE_MAPPING_IMAGE;
|
if (protect & VPROT_IMAGE) mapping_access |= FILE_MAPPING_IMAGE;
|
||||||
else if (protect & VPROT_WRITE) mapping_access |= FILE_MAPPING_WRITE;
|
else if (protect & VPROT_WRITE) mapping_access |= FILE_MAPPING_WRITE;
|
||||||
mapping->fd = dup_fd_object( fd, mapping_access,
|
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
if (!(mapping->fd = get_fd_object_for_mapping( fd, mapping_access, sharing )))
|
||||||
FILE_SYNCHRONOUS_IO_NONALERT );
|
{
|
||||||
|
mapping->fd = dup_fd_object( fd, mapping_access, sharing, FILE_SYNCHRONOUS_IO_NONALERT );
|
||||||
|
if (mapping->fd) set_fd_user( mapping->fd, &mapping_fd_ops, NULL );
|
||||||
|
}
|
||||||
release_object( file );
|
release_object( file );
|
||||||
release_object( fd );
|
release_object( fd );
|
||||||
if (!mapping->fd) goto error;
|
if (!mapping->fd) goto error;
|
||||||
|
|
||||||
set_fd_user( mapping->fd, &mapping_fd_ops, &mapping->obj );
|
|
||||||
if ((unix_fd = get_unix_fd( mapping->fd )) == -1) goto error;
|
if ((unix_fd = get_unix_fd( mapping->fd )) == -1) goto error;
|
||||||
if (protect & VPROT_IMAGE)
|
if (protect & VPROT_IMAGE)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue