Lines Matching refs:file
28 * Global file hash table
46 static inline void nlm_debug_print_file(char *msg, struct nlm_file *file)
48 struct inode *inode = nlmsvc_file_inode(file);
59 static inline void nlm_debug_print_file(char *msg, struct nlm_file *file)
80 * Open the file. Note that if we're reexporting, for example,
84 * the file.
87 struct nlm_file *file, int mode)
89 struct file **fp = &file->f_file[mode];
94 nfserr = nlmsvc_ops->fopen(rqstp, &file->f_handle, fp, mode);
101 * Lookup file info. If it doesn't exist, create a file info struct
102 * and open a (VFS) file for the given inode.
108 struct nlm_file *file;
118 /* Lock file table */
121 hlist_for_each_entry(file, &nlm_files[hash], f_list)
122 if (!nfs_compare_fh(&file->f_handle, &lock->fh)) {
123 mutex_lock(&file->f_mutex);
124 nfserr = nlm_do_fopen(rqstp, file, mode);
125 mutex_unlock(&file->f_mutex);
128 nlm_debug_print_fh("creating file for", &lock->fh);
131 file = kzalloc(sizeof(*file), GFP_KERNEL);
132 if (!file)
135 memcpy(&file->f_handle, &lock->fh, sizeof(struct nfs_fh));
136 mutex_init(&file->f_mutex);
137 INIT_HLIST_NODE(&file->f_list);
138 INIT_LIST_HEAD(&file->f_blocks);
140 nfserr = nlm_do_fopen(rqstp, file, mode);
144 hlist_add_head(&file->f_list, &nlm_files[hash]);
147 dprintk("lockd: found file %p (count %d)\n", file, file->f_count);
148 *result = file;
149 file->f_count++;
156 kfree(file);
161 * Delete a file after having released all locks, blocks and shares
164 nlm_delete_file(struct nlm_file *file)
166 nlm_debug_print_file("closing file", file);
167 if (!hlist_unhashed(&file->f_list)) {
168 hlist_del(&file->f_list);
169 if (file->f_file[O_RDONLY])
170 nlmsvc_ops->fclose(file->f_file[O_RDONLY]);
171 if (file->f_file[O_WRONLY])
172 nlmsvc_ops->fclose(file->f_file[O_WRONLY]);
173 kfree(file);
175 printk(KERN_WARNING "lockd: attempt to release unknown file!\n");
179 static int nlm_unlock_files(struct nlm_file *file, const struct file_lock *fl)
191 lock.c.flc_file = file->f_file[O_RDONLY];
194 lock.c.flc_file = file->f_file[O_WRONLY];
204 * Loop over all locks on the given file and perform the specified
208 nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
211 struct inode *inode = nlmsvc_file_inode(file);
219 file->f_locks = 0;
226 file->f_locks++;
232 if (nlm_unlock_files(file, fl))
249 * Inspect a single file
252 nlm_inspect_file(struct nlm_host *host, struct nlm_file *file, nlm_host_match_fn_t match)
254 nlmsvc_traverse_blocks(host, file, match);
255 nlmsvc_traverse_shares(host, file, match);
256 return nlm_traverse_locks(host, file, match);
261 * shares on a given file.
264 nlm_file_inuse(struct nlm_file *file)
266 struct inode *inode = nlmsvc_file_inode(file);
270 if (file->f_count || !list_empty(&file->f_blocks) || file->f_shares)
283 file->f_locks = 0;
287 static void nlm_close_files(struct nlm_file *file)
289 if (file->f_file[O_RDONLY])
290 nlmsvc_ops->fclose(file->f_file[O_RDONLY]);
291 if (file->f_file[O_WRONLY])
292 nlmsvc_ops->fclose(file->f_file[O_WRONLY]);
296 * Loop over all files in the file table.
300 int (*is_failover_file)(void *data, struct nlm_file *file))
303 struct nlm_file *file;
308 hlist_for_each_entry_safe(file, next, &nlm_files[i], f_list) {
309 if (is_failover_file && !is_failover_file(data, file))
311 file->f_count++;
314 /* Traverse locks, blocks and shares of this file
315 * and update file->f_locks count */
316 if (nlm_inspect_file(data, file, match))
320 file->f_count--;
321 /* No more references to this file. Let go of it. */
322 if (list_empty(&file->f_blocks) && !file->f_locks
323 && !file->f_shares && !file->f_count) {
324 hlist_del(&file->f_list);
325 nlm_close_files(file);
326 kfree(file);
335 * Release file. If there are no more remote locks on this file,
344 nlm_release_file(struct nlm_file *file)
347 file, file->f_count);
349 /* Lock file table */
352 /* If there are no more locks etc, delete the file */
353 if (--file->f_count == 0 && !nlm_file_inuse(file))
354 nlm_delete_file(file);
461 nlmsvc_match_sb(void *datap, struct nlm_file *file)
465 return sb == nlmsvc_file_inode(file)->i_sb;
469 * nlmsvc_unlock_all_by_sb - release locks held on this file system
472 * Release all locks held by clients accessing this file system.