Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2001 Clemson University and The University of Chicago |
| 3 | * |
| 4 | * See COPYING in top-level directory. |
| 5 | */ |
| 6 | |
| 7 | #include "protocol.h" |
Mike Marshall | 575e946 | 2015-12-04 12:56:14 -0500 | [diff] [blame] | 8 | #include "orangefs-kernel.h" |
| 9 | #include "orangefs-bufmap.h" |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 10 | |
| 11 | struct readdir_handle_s { |
| 12 | int buffer_index; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 13 | struct orangefs_readdir_response_s readdir_response; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 14 | void *dents_buf; |
| 15 | }; |
| 16 | |
| 17 | /* |
| 18 | * decode routine needed by kmod to make sense of the shared page for readdirs. |
| 19 | */ |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 20 | static long decode_dirents(char *ptr, size_t size, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 21 | struct orangefs_readdir_response_s *readdir) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 22 | { |
| 23 | int i; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 24 | struct orangefs_readdir_response_s *rd = |
| 25 | (struct orangefs_readdir_response_s *) ptr; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 26 | char *buf = ptr; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 27 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 28 | if (size < offsetof(struct orangefs_readdir_response_s, dirent_array)) |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 29 | return -EINVAL; |
| 30 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 31 | readdir->token = rd->token; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 32 | readdir->orangefs_dirent_outcount = rd->orangefs_dirent_outcount; |
| 33 | readdir->dirent_array = kcalloc(readdir->orangefs_dirent_outcount, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 34 | sizeof(*readdir->dirent_array), |
| 35 | GFP_KERNEL); |
| 36 | if (readdir->dirent_array == NULL) |
| 37 | return -ENOMEM; |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 38 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 39 | buf += offsetof(struct orangefs_readdir_response_s, dirent_array); |
| 40 | size -= offsetof(struct orangefs_readdir_response_s, dirent_array); |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 41 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 42 | for (i = 0; i < readdir->orangefs_dirent_outcount; i++) { |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 43 | __u32 len; |
| 44 | |
| 45 | if (size < 4) |
| 46 | goto Einval; |
| 47 | |
| 48 | len = *(__u32 *)buf; |
| 49 | if (len >= (unsigned)-24) |
| 50 | goto Einval; |
| 51 | |
Al Viro | 9be68b0 | 2015-10-09 17:43:15 -0400 | [diff] [blame] | 52 | readdir->dirent_array[i].d_name = buf + 4; |
Al Viro | 9be68b0 | 2015-10-09 17:43:15 -0400 | [diff] [blame] | 53 | readdir->dirent_array[i].d_length = len; |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 54 | |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame^] | 55 | /* |
| 56 | * Round 4 + len + 1, which is the encoded size plus the string |
| 57 | * plus the null terminator to the nearest eight byte boundry. |
| 58 | */ |
| 59 | len = ((4 + len + 1) + 7) & ~7; |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 60 | if (size < len + 16) |
| 61 | goto Einval; |
| 62 | size -= len + 16; |
| 63 | |
| 64 | buf += len; |
| 65 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 66 | readdir->dirent_array[i].khandle = |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 67 | *(struct orangefs_khandle *) buf; |
Al Viro | 9be68b0 | 2015-10-09 17:43:15 -0400 | [diff] [blame] | 68 | buf += 16; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 69 | } |
Al Viro | 9be68b0 | 2015-10-09 17:43:15 -0400 | [diff] [blame] | 70 | return buf - ptr; |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 71 | Einval: |
| 72 | kfree(readdir->dirent_array); |
| 73 | readdir->dirent_array = NULL; |
| 74 | return -EINVAL; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static long readdir_handle_ctor(struct readdir_handle_s *rhandle, void *buf, |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 78 | size_t size, int buffer_index) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 79 | { |
| 80 | long ret; |
| 81 | |
| 82 | if (buf == NULL) { |
| 83 | gossip_err |
| 84 | ("Invalid NULL buffer specified in readdir_handle_ctor\n"); |
| 85 | return -ENOMEM; |
| 86 | } |
| 87 | if (buffer_index < 0) { |
| 88 | gossip_err |
| 89 | ("Invalid buffer index specified in readdir_handle_ctor\n"); |
| 90 | return -EINVAL; |
| 91 | } |
| 92 | rhandle->buffer_index = buffer_index; |
| 93 | rhandle->dents_buf = buf; |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 94 | ret = decode_dirents(buf, size, &rhandle->readdir_response); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 95 | if (ret < 0) { |
| 96 | gossip_err("Could not decode readdir from buffer %ld\n", ret); |
| 97 | rhandle->buffer_index = -1; |
| 98 | gossip_debug(GOSSIP_DIR_DEBUG, "vfree %p\n", buf); |
| 99 | vfree(buf); |
| 100 | rhandle->dents_buf = NULL; |
| 101 | } |
| 102 | return ret; |
| 103 | } |
| 104 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 105 | static void readdir_handle_dtor(struct orangefs_bufmap *bufmap, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 106 | struct readdir_handle_s *rhandle) |
| 107 | { |
| 108 | if (rhandle == NULL) |
| 109 | return; |
| 110 | |
| 111 | /* kfree(NULL) is safe */ |
| 112 | kfree(rhandle->readdir_response.dirent_array); |
| 113 | rhandle->readdir_response.dirent_array = NULL; |
| 114 | |
| 115 | if (rhandle->buffer_index >= 0) { |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame^] | 116 | orangefs_readdir_index_put(bufmap, rhandle->buffer_index); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 117 | rhandle->buffer_index = -1; |
| 118 | } |
| 119 | if (rhandle->dents_buf) { |
| 120 | gossip_debug(GOSSIP_DIR_DEBUG, "vfree %p\n", |
| 121 | rhandle->dents_buf); |
| 122 | vfree(rhandle->dents_buf); |
| 123 | rhandle->dents_buf = NULL; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Read directory entries from an instance of an open directory. |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 129 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 130 | static int orangefs_readdir(struct file *file, struct dir_context *ctx) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 131 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 132 | struct orangefs_bufmap *bufmap = NULL; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 133 | int ret = 0; |
| 134 | int buffer_index; |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 135 | /* |
| 136 | * ptoken supports Orangefs' distributed directory logic, added |
| 137 | * in 2.9.2. |
| 138 | */ |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 139 | __u64 *ptoken = file->private_data; |
| 140 | __u64 pos = 0; |
| 141 | ino_t ino = 0; |
| 142 | struct dentry *dentry = file->f_path.dentry; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 143 | struct orangefs_kernel_op_s *new_op = NULL; |
| 144 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(dentry->d_inode); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 145 | int buffer_full = 0; |
| 146 | struct readdir_handle_s rhandle; |
| 147 | int i = 0; |
| 148 | int len = 0; |
| 149 | ino_t current_ino = 0; |
| 150 | char *current_entry = NULL; |
| 151 | long bytes_decoded; |
| 152 | |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 153 | gossip_debug(GOSSIP_DIR_DEBUG, |
| 154 | "%s: ctx->pos:%lld, ptoken = %llu\n", |
| 155 | __func__, |
| 156 | lld(ctx->pos), |
| 157 | llu(*ptoken)); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 158 | |
| 159 | pos = (__u64) ctx->pos; |
| 160 | |
| 161 | /* are we done? */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 162 | if (pos == ORANGEFS_READDIR_END) { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 163 | gossip_debug(GOSSIP_DIR_DEBUG, |
| 164 | "Skipping to termination path\n"); |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | gossip_debug(GOSSIP_DIR_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 169 | "orangefs_readdir called on %s (pos=%llu)\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 170 | dentry->d_name.name, llu(pos)); |
| 171 | |
| 172 | rhandle.buffer_index = -1; |
| 173 | rhandle.dents_buf = NULL; |
| 174 | memset(&rhandle.readdir_response, 0, sizeof(rhandle.readdir_response)); |
| 175 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 176 | new_op = op_alloc(ORANGEFS_VFS_OP_READDIR); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 177 | if (!new_op) |
| 178 | return -ENOMEM; |
| 179 | |
| 180 | new_op->uses_shared_memory = 1; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 181 | new_op->upcall.req.readdir.refn = orangefs_inode->refn; |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame^] | 182 | new_op->upcall.req.readdir.max_dirent_count = |
| 183 | ORANGEFS_MAX_DIRENT_COUNT_READDIR; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 184 | |
| 185 | gossip_debug(GOSSIP_DIR_DEBUG, |
| 186 | "%s: upcall.req.readdir.refn.khandle: %pU\n", |
| 187 | __func__, |
| 188 | &new_op->upcall.req.readdir.refn.khandle); |
| 189 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 190 | new_op->upcall.req.readdir.token = *ptoken; |
| 191 | |
| 192 | get_new_buffer_index: |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame^] | 193 | ret = orangefs_readdir_index_get(&bufmap, &buffer_index); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 194 | if (ret < 0) { |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame^] | 195 | gossip_lerr("orangefs_readdir: orangefs_readdir_index_get() failure (%d)\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 196 | ret); |
| 197 | goto out_free_op; |
| 198 | } |
| 199 | new_op->upcall.req.readdir.buf_index = buffer_index; |
| 200 | |
| 201 | ret = service_operation(new_op, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 202 | "orangefs_readdir", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 203 | get_interruptible_flag(dentry->d_inode)); |
| 204 | |
| 205 | gossip_debug(GOSSIP_DIR_DEBUG, |
| 206 | "Readdir downcall status is %d. ret:%d\n", |
| 207 | new_op->downcall.status, |
| 208 | ret); |
| 209 | |
| 210 | if (ret == -EAGAIN && op_state_purged(new_op)) { |
| 211 | /* |
| 212 | * readdir shared memory aread has been wiped due to |
| 213 | * pvfs2-client-core restarting, so we must get a new |
| 214 | * index into the shared memory. |
| 215 | */ |
| 216 | gossip_debug(GOSSIP_DIR_DEBUG, |
| 217 | "%s: Getting new buffer_index for retry of readdir..\n", |
| 218 | __func__); |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame^] | 219 | orangefs_readdir_index_put(bufmap, buffer_index); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 220 | goto get_new_buffer_index; |
| 221 | } |
| 222 | |
| 223 | if (ret == -EIO && op_state_purged(new_op)) { |
| 224 | gossip_err("%s: Client is down. Aborting readdir call.\n", |
| 225 | __func__); |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame^] | 226 | orangefs_readdir_index_put(bufmap, buffer_index); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 227 | goto out_free_op; |
| 228 | } |
| 229 | |
| 230 | if (ret < 0 || new_op->downcall.status != 0) { |
| 231 | gossip_debug(GOSSIP_DIR_DEBUG, |
| 232 | "Readdir request failed. Status:%d\n", |
| 233 | new_op->downcall.status); |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame^] | 234 | orangefs_readdir_index_put(bufmap, buffer_index); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 235 | if (ret >= 0) |
| 236 | ret = new_op->downcall.status; |
| 237 | goto out_free_op; |
| 238 | } |
| 239 | |
| 240 | bytes_decoded = |
| 241 | readdir_handle_ctor(&rhandle, |
| 242 | new_op->downcall.trailer_buf, |
Al Viro | 8092895 | 2015-10-09 18:11:10 -0400 | [diff] [blame] | 243 | new_op->downcall.trailer_size, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 244 | buffer_index); |
| 245 | if (bytes_decoded < 0) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 246 | gossip_err("orangefs_readdir: Could not decode trailer buffer into a readdir response %d\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 247 | ret); |
| 248 | ret = bytes_decoded; |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame^] | 249 | orangefs_readdir_index_put(bufmap, buffer_index); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 250 | goto out_free_op; |
| 251 | } |
| 252 | |
| 253 | if (bytes_decoded != new_op->downcall.trailer_size) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 254 | gossip_err("orangefs_readdir: # bytes decoded (%ld) " |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 255 | "!= trailer size (%ld)\n", |
| 256 | bytes_decoded, |
| 257 | (long)new_op->downcall.trailer_size); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 258 | ret = -EINVAL; |
| 259 | goto out_destroy_handle; |
| 260 | } |
| 261 | |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 262 | /* |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 263 | * orangefs doesn't actually store dot and dot-dot, but |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 264 | * we need to have them represented. |
| 265 | */ |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 266 | if (pos == 0) { |
| 267 | ino = get_ino_from_khandle(dentry->d_inode); |
| 268 | gossip_debug(GOSSIP_DIR_DEBUG, |
| 269 | "%s: calling dir_emit of \".\" with pos = %llu\n", |
| 270 | __func__, |
| 271 | llu(pos)); |
| 272 | ret = dir_emit(ctx, ".", 1, ino, DT_DIR); |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 273 | pos += 1; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | if (pos == 1) { |
| 277 | ino = get_parent_ino_from_dentry(dentry); |
| 278 | gossip_debug(GOSSIP_DIR_DEBUG, |
| 279 | "%s: calling dir_emit of \"..\" with pos = %llu\n", |
| 280 | __func__, |
| 281 | llu(pos)); |
| 282 | ret = dir_emit(ctx, "..", 2, ino, DT_DIR); |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 283 | pos += 1; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 284 | } |
| 285 | |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 286 | /* |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 287 | * we stored ORANGEFS_ITERATE_NEXT in ctx->pos last time around |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 288 | * to prevent "finding" dot and dot-dot on any iteration |
| 289 | * other than the first. |
| 290 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 291 | if (ctx->pos == ORANGEFS_ITERATE_NEXT) |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 292 | ctx->pos = 0; |
| 293 | |
| 294 | for (i = ctx->pos; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 295 | i < rhandle.readdir_response.orangefs_dirent_outcount; |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 296 | i++) { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 297 | len = rhandle.readdir_response.dirent_array[i].d_length; |
| 298 | current_entry = rhandle.readdir_response.dirent_array[i].d_name; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 299 | current_ino = orangefs_khandle_to_ino( |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 300 | &(rhandle.readdir_response.dirent_array[i].khandle)); |
| 301 | |
| 302 | gossip_debug(GOSSIP_DIR_DEBUG, |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 303 | "calling dir_emit for %s with len %d" |
| 304 | ", ctx->pos %ld\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 305 | current_entry, |
| 306 | len, |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 307 | (unsigned long)ctx->pos); |
| 308 | /* |
| 309 | * type is unknown. We don't return object type |
| 310 | * in the dirent_array. This leaves getdents |
| 311 | * clueless about type. |
| 312 | */ |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 313 | ret = |
| 314 | dir_emit(ctx, current_entry, len, current_ino, DT_UNKNOWN); |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 315 | if (!ret) |
| 316 | break; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 317 | ctx->pos++; |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 318 | gossip_debug(GOSSIP_DIR_DEBUG, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 319 | "%s: ctx->pos:%lld\n", |
| 320 | __func__, |
| 321 | lld(ctx->pos)); |
| 322 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 323 | } |
| 324 | |
Mike Marshall | 5480494 | 2015-10-05 13:44:24 -0400 | [diff] [blame] | 325 | /* |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 326 | * we ran all the way through the last batch, set up for |
| 327 | * getting another batch... |
| 328 | */ |
| 329 | if (ret) { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 330 | *ptoken = rhandle.readdir_response.token; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 331 | ctx->pos = ORANGEFS_ITERATE_NEXT; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /* |
| 335 | * Did we hit the end of the directory? |
| 336 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 337 | if (rhandle.readdir_response.token == ORANGEFS_READDIR_END && |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 338 | !buffer_full) { |
Mike Marshall | 88309aa | 2015-09-23 16:48:40 -0400 | [diff] [blame] | 339 | gossip_debug(GOSSIP_DIR_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 340 | "End of dir detected; setting ctx->pos to ORANGEFS_READDIR_END.\n"); |
| 341 | ctx->pos = ORANGEFS_READDIR_END; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 342 | } |
| 343 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 344 | out_destroy_handle: |
| 345 | readdir_handle_dtor(bufmap, &rhandle); |
| 346 | out_free_op: |
| 347 | op_release(new_op); |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 348 | gossip_debug(GOSSIP_DIR_DEBUG, "orangefs_readdir returning %d\n", ret); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 349 | return ret; |
| 350 | } |
| 351 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 352 | static int orangefs_dir_open(struct inode *inode, struct file *file) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 353 | { |
| 354 | __u64 *ptoken; |
| 355 | |
| 356 | file->private_data = kmalloc(sizeof(__u64), GFP_KERNEL); |
| 357 | if (!file->private_data) |
| 358 | return -ENOMEM; |
| 359 | |
| 360 | ptoken = file->private_data; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 361 | *ptoken = ORANGEFS_READDIR_START; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 362 | return 0; |
| 363 | } |
| 364 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 365 | static int orangefs_dir_release(struct inode *inode, struct file *file) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 366 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 367 | orangefs_flush_inode(inode); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 368 | kfree(file->private_data); |
| 369 | return 0; |
| 370 | } |
| 371 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 372 | /** ORANGEFS implementation of VFS directory operations */ |
| 373 | const struct file_operations orangefs_dir_operations = { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 374 | .read = generic_read_dir, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 375 | .iterate = orangefs_readdir, |
| 376 | .open = orangefs_dir_open, |
| 377 | .release = orangefs_dir_release, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 378 | }; |