Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | /* * linux/fs/nfs/unlink.c * * nfs sillydelete handling * * NOTE: we rely on holding the BKL for list manipulation protection. */ #include <linux/slab.h> #include <linux/string.h> #include <linux/dcache.h> #include <linux/sunrpc/sched.h> #include <linux/sunrpc/clnt.h> #include <linux/nfs_fs.h> struct nfs_unlinkdata { struct nfs_unlinkdata *next; struct dentry *dir, *dentry; struct qstr name; struct rpc_task task; struct rpc_cred *cred; unsigned int count; }; static struct nfs_unlinkdata *nfs_deletes; static RPC_WAITQ(nfs_delete_queue, "nfs_delete_queue"); /** * nfs_detach_unlinkdata - Remove asynchronous unlink from global list * @data: pointer to descriptor */ static inline void nfs_detach_unlinkdata(struct nfs_unlinkdata *data) { struct nfs_unlinkdata **q; for (q = &nfs_deletes; *q != NULL; q = &((*q)->next)) { if (*q == data) { *q = data->next; break; } } } /** * nfs_put_unlinkdata - release data from a sillydelete operation. * @data: pointer to unlink structure. */ static void nfs_put_unlinkdata(struct nfs_unlinkdata *data) { if (--data->count == 0) { nfs_detach_unlinkdata(data); if (data->name.name != NULL) kfree(data->name.name); kfree(data); } } #define NAME_ALLOC_LEN(len) ((len+16) & ~15) /** * nfs_copy_dname - copy dentry name to data structure * @dentry: pointer to dentry * @data: nfs_unlinkdata */ static inline void nfs_copy_dname(struct dentry *dentry, struct nfs_unlinkdata *data) { char *str; int len = dentry->d_name.len; str = kmalloc(NAME_ALLOC_LEN(len), GFP_KERNEL); if (!str) return; memcpy(str, dentry->d_name.name, len); if (!data->name.len) { data->name.len = len; data->name.name = str; } else kfree(str); } /** * nfs_async_unlink_init - Initialize the RPC info * @task: rpc_task of the sillydelete * * We delay initializing RPC info until after the call to dentry_iput() * in order to minimize races against rename(). */ static void nfs_async_unlink_init(struct rpc_task *task) { struct nfs_unlinkdata *data = (struct nfs_unlinkdata *)task->tk_calldata; struct dentry *dir = data->dir; struct rpc_message msg = { .rpc_cred = data->cred, }; int status = -ENOENT; if (!data->name.len) goto out_err; status = NFS_PROTO(dir->d_inode)->unlink_setup(&msg, dir, &data->name); if (status < 0) goto out_err; rpc_call_setup(task, &msg, 0); return; out_err: rpc_exit(task, status); } /** * nfs_async_unlink_done - Sillydelete post-processing * @task: rpc_task of the sillydelete * * Do the directory attribute update. */ static void nfs_async_unlink_done(struct rpc_task *task) { struct nfs_unlinkdata *data = (struct nfs_unlinkdata *)task->tk_calldata; struct dentry *dir = data->dir; struct inode *dir_i; if (!dir) return; dir_i = dir->d_inode; nfs_zap_caches(dir_i); if (NFS_PROTO(dir_i)->unlink_done(dir, task)) return; put_rpccred(data->cred); data->cred = NULL; dput(dir); } /** * nfs_async_unlink_release - Release the sillydelete data. * @task: rpc_task of the sillydelete * * We need to call nfs_put_unlinkdata as a 'tk_release' task since the * rpc_task would be freed too. */ static void nfs_async_unlink_release(struct rpc_task *task) { struct nfs_unlinkdata *data = (struct nfs_unlinkdata *)task->tk_calldata; nfs_put_unlinkdata(data); } /** * nfs_async_unlink - asynchronous unlinking of a file * @dir: directory in which the file resides. * @name: name of the file to unlink. */ int nfs_async_unlink(struct dentry *dentry) { struct dentry *dir = dentry->d_parent; struct nfs_unlinkdata *data; struct rpc_task *task; struct rpc_clnt *clnt = NFS_CLIENT(dir->d_inode); int status = -ENOMEM; data = kmalloc(sizeof(*data), GFP_KERNEL); if (!data) goto out; memset(data, 0, sizeof(*data)); data->dir = dget(dir); data->dentry = dentry; data->next = nfs_deletes; nfs_deletes = data; data->count = 1; task = &data->task; rpc_init_task(task, clnt, nfs_async_unlink_done , RPC_TASK_ASYNC); task->tk_calldata = data; task->tk_action = nfs_async_unlink_init; task->tk_release = nfs_async_unlink_release; dentry->d_flags |= DCACHE_NFSFS_RENAMED; data->cred = rpcauth_lookupcred(clnt->cl_auth, 0); rpc_sleep_on(&nfs_delete_queue, task, NULL, NULL); status = 0; out: return status; } /** * nfs_complete_remove - Initialize completion of the sillydelete * @dentry: dentry to delete * * Since we're most likely to be called by dentry_iput(), we * only use the dentry to find the sillydelete. We then copy the name * into the qstr. */ void nfs_complete_unlink(struct dentry *dentry) { struct nfs_unlinkdata *data; for(data = nfs_deletes; data != NULL; data = data->next) { if (dentry == data->dentry) break; } if (!data) return; data->count++; nfs_copy_dname(dentry, data); dentry->d_flags &= ~DCACHE_NFSFS_RENAMED; if (data->task.tk_rpcwait == &nfs_delete_queue) rpc_wake_up_task(&data->task); nfs_put_unlinkdata(data); } |