Fsfilec

static int expand_fdtable(struct files_struct *files, int nr) {

struct fdtable *new_fdt, *cur_fdt;

spin_unlock(&files->file_lock); new_fdt = alloc_fdtable(nr); spin_lock(&files->file_lock);

copy_fdtable(new_fdt, cur_fdt); rcu_assign_pointer(files->fdt, new_fdt); if (cur_fdt->max_fds > NR_OPEN_DEFAULT) free_fdtable(cur_fdt);

return 1;

alloc_fdtable allocates a file descriptor table with the maximal number of possible entries and also reserves memory for the enlarged bitmaps — it only makes sense to increase all components at the same time. After this, the function copies the previous contents of the file descriptor table into the new, enlarged instance. Switching the pointer files_fdt to the new instance is handled by the RCU function rcu_assign_pointer as described in Chapter 5. After this, the old file descriptor table can be freed.

8 Actually, this is slightly more complicated in reality because the RCU mechanism is used to make the freeing of file instances more efficient. Since this only complicates things, but does not add new insights. I am not going to discuss it any further.

Continue reading here: File Operations

Was this article helpful?

0 0