Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1 | /* |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 2 | * Copyright 2017 Omnibond Systems, L.L.C. |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | #include "protocol.h" |
Mike Marshall | 575e946 | 2015-12-04 12:56:14 -0500 | [diff] [blame] | 6 | #include "orangefs-kernel.h" |
| 7 | #include "orangefs-bufmap.h" |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 8 | |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 9 | struct orangefs_dir_part { |
| 10 | struct orangefs_dir_part *next; |
| 11 | size_t len; |
| 12 | }; |
| 13 | |
| 14 | struct orangefs_dir { |
| 15 | __u64 token; |
| 16 | struct orangefs_dir_part *part; |
| 17 | loff_t end; |
| 18 | int error; |
| 19 | }; |
| 20 | |
| 21 | #define PART_SHIFT (24) |
| 22 | #define PART_SIZE (1<<24) |
| 23 | #define PART_MASK (~(PART_SIZE - 1)) |
| 24 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 25 | /* |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 26 | * There can be up to 512 directory entries. Each entry is encoded as |
| 27 | * follows: |
| 28 | * 4 bytes: string size (n) |
| 29 | * n bytes: string |
| 30 | * 1 byte: trailing zero |
| 31 | * padding to 8 bytes |
| 32 | * 16 bytes: khandle |
| 33 | * padding to 8 bytes |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 34 | * |
| 35 | * The trailer_buf starts with a struct orangefs_readdir_response_s |
| 36 | * which must be skipped to get to the directory data. |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 37 | * |
| 38 | * The data which is received from the userspace daemon is termed a |
| 39 | * part and is stored in a linked list in case more than one part is |
| 40 | * needed for a large directory. |
| 41 | * |
| 42 | * The position pointer (ctx->pos) encodes the part and offset on which |
| 43 | * to begin reading at. Bits above PART_SHIFT encode the part and bits |
| 44 | * below PART_SHIFT encode the offset. Parts are stored in a linked |
| 45 | * list which grows as data is received from the server. The overhead |
| 46 | * associated with managing the list is presumed to be small compared to |
| 47 | * the overhead of communicating with the server. |
| 48 | * |
| 49 | * As data is received from the server, it is placed at the end of the |
| 50 | * part list. Data is parsed from the current position as it is needed. |
| 51 | * When data is determined to be corrupt, it is either because the |
| 52 | * userspace component has sent back corrupt data or because the file |
| 53 | * pointer has been moved to an invalid location. Since the two cannot |
| 54 | * be differentiated, return EIO. |
| 55 | * |
| 56 | * Part zero is synthesized to contains `.' and `..'. Part one is the |
| 57 | * first part of the part list. |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 58 | */ |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 59 | |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 60 | static int do_readdir(struct orangefs_inode_s *oi, |
| 61 | struct orangefs_dir *od, struct dentry *dentry, |
| 62 | struct orangefs_kernel_op_s *op) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 63 | { |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 64 | struct orangefs_readdir_response_s *resp; |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 65 | int bufi, r; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 66 | |
Martin Brandenburg | ee3b8d3 | 2016-02-17 12:55:42 -0500 | [diff] [blame] | 67 | /* |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 68 | * Despite the badly named field, readdir does not use shared |
| 69 | * memory. However, there are a limited number of readdir |
| 70 | * slots, which must be allocated here. This flag simply tells |
| 71 | * the op scheduler to return the op here for retry. |
Martin Brandenburg | ee3b8d3 | 2016-02-17 12:55:42 -0500 | [diff] [blame] | 72 | */ |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 73 | op->uses_shared_memory = 1; |
| 74 | op->upcall.req.readdir.refn = oi->refn; |
| 75 | op->upcall.req.readdir.token = od->token; |
| 76 | op->upcall.req.readdir.max_dirent_count = |
Martin Brandenburg | 7d22148 | 2016-01-04 15:05:28 -0500 | [diff] [blame] | 77 | ORANGEFS_MAX_DIRENT_COUNT_READDIR; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 78 | |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 79 | again: |
| 80 | bufi = orangefs_readdir_index_get(); |
| 81 | if (bufi < 0) { |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 82 | od->error = bufi; |
| 83 | return bufi; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 86 | op->upcall.req.readdir.buf_index = bufi; |
| 87 | |
| 88 | r = service_operation(op, "orangefs_readdir", |
| 89 | get_interruptible_flag(dentry->d_inode)); |
| 90 | |
| 91 | orangefs_readdir_index_put(bufi); |
| 92 | |
| 93 | if (op_state_purged(op)) { |
| 94 | if (r == -EAGAIN) { |
| 95 | vfree(op->downcall.trailer_buf); |
| 96 | goto again; |
| 97 | } else if (r == -EIO) { |
| 98 | vfree(op->downcall.trailer_buf); |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 99 | od->error = r; |
| 100 | return r; |
| 101 | } |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 104 | if (r < 0) { |
| 105 | vfree(op->downcall.trailer_buf); |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 106 | od->error = r; |
| 107 | return r; |
| 108 | } else if (op->downcall.status) { |
| 109 | vfree(op->downcall.trailer_buf); |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 110 | od->error = op->downcall.status; |
| 111 | return op->downcall.status; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 112 | } |
| 113 | |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 114 | /* |
| 115 | * The maximum size is size per entry times the 512 entries plus |
| 116 | * the header. This is well under the limit. |
| 117 | */ |
| 118 | if (op->downcall.trailer_size > PART_SIZE) { |
| 119 | vfree(op->downcall.trailer_buf); |
| 120 | od->error = -EIO; |
| 121 | return -EIO; |
| 122 | } |
| 123 | |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 124 | resp = (struct orangefs_readdir_response_s *) |
| 125 | op->downcall.trailer_buf; |
| 126 | od->token = resp->token; |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 127 | return 0; |
| 128 | } |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 129 | |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 130 | static int parse_readdir(struct orangefs_dir *od, |
| 131 | struct orangefs_kernel_op_s *op) |
| 132 | { |
| 133 | struct orangefs_dir_part *part, *new; |
| 134 | size_t count; |
| 135 | |
| 136 | count = 1; |
| 137 | part = od->part; |
| 138 | while (part && part->next) { |
| 139 | part = part->next; |
| 140 | count++; |
Al Viro | 9f5e2f7 | 2016-02-16 19:54:13 -0500 | [diff] [blame] | 141 | } |
| 142 | |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 143 | new = (void *)op->downcall.trailer_buf; |
| 144 | new->next = NULL; |
| 145 | new->len = op->downcall.trailer_size - |
| 146 | sizeof(struct orangefs_readdir_response_s); |
| 147 | if (!od->part) |
| 148 | od->part = new; |
| 149 | else |
| 150 | part->next = new; |
| 151 | count++; |
| 152 | od->end = count << PART_SHIFT; |
| 153 | |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 154 | return 0; |
| 155 | } |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 156 | |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 157 | static int orangefs_dir_more(struct orangefs_inode_s *oi, |
| 158 | struct orangefs_dir *od, struct dentry *dentry) |
| 159 | { |
| 160 | struct orangefs_kernel_op_s *op; |
| 161 | int r; |
| 162 | |
| 163 | op = op_alloc(ORANGEFS_VFS_OP_READDIR); |
| 164 | if (!op) { |
| 165 | od->error = -ENOMEM; |
| 166 | return -ENOMEM; |
| 167 | } |
| 168 | r = do_readdir(oi, od, dentry, op); |
| 169 | if (r) { |
| 170 | od->error = r; |
| 171 | goto out; |
| 172 | } |
| 173 | r = parse_readdir(od, op); |
| 174 | if (r) { |
| 175 | od->error = r; |
| 176 | goto out; |
| 177 | } |
| 178 | |
| 179 | od->error = 0; |
| 180 | out: |
| 181 | op_release(op); |
| 182 | return od->error; |
| 183 | } |
| 184 | |
| 185 | static int fill_from_part(struct orangefs_dir_part *part, |
| 186 | struct dir_context *ctx) |
| 187 | { |
| 188 | const int offset = sizeof(struct orangefs_readdir_response_s); |
| 189 | struct orangefs_khandle *khandle; |
| 190 | __u32 *len, padlen; |
| 191 | loff_t i; |
| 192 | char *s; |
| 193 | i = ctx->pos & ~PART_MASK; |
| 194 | |
| 195 | /* The file offset from userspace is too large. */ |
| 196 | if (i > part->len) |
Martin Brandenburg | bf15ba7 | 2017-05-02 12:15:10 -0400 | [diff] [blame] | 197 | return 1; |
| 198 | |
| 199 | /* |
| 200 | * If the seek pointer is positioned just before an entry it |
| 201 | * should find the next entry. |
| 202 | */ |
| 203 | if (i % 8) |
| 204 | i = i + (8 - i%8)%8; |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 205 | |
| 206 | while (i < part->len) { |
| 207 | if (part->len < i + sizeof *len) |
Martin Brandenburg | bf15ba7 | 2017-05-02 12:15:10 -0400 | [diff] [blame] | 208 | break; |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 209 | len = (void *)part + offset + i; |
| 210 | /* |
| 211 | * len is the size of the string itself. padlen is the |
| 212 | * total size of the encoded string. |
| 213 | */ |
| 214 | padlen = (sizeof *len + *len + 1) + |
| 215 | (8 - (sizeof *len + *len + 1)%8)%8; |
| 216 | if (part->len < i + padlen + sizeof *khandle) |
Martin Brandenburg | bf15ba7 | 2017-05-02 12:15:10 -0400 | [diff] [blame] | 217 | goto next; |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 218 | s = (void *)part + offset + i + sizeof *len; |
| 219 | if (s[*len] != 0) |
Martin Brandenburg | bf15ba7 | 2017-05-02 12:15:10 -0400 | [diff] [blame] | 220 | goto next; |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 221 | khandle = (void *)part + offset + i + padlen; |
| 222 | if (!dir_emit(ctx, s, *len, |
| 223 | orangefs_khandle_to_ino(khandle), |
| 224 | DT_UNKNOWN)) |
| 225 | return 0; |
| 226 | i += padlen + sizeof *khandle; |
| 227 | i = i + (8 - i%8)%8; |
| 228 | BUG_ON(i > part->len); |
| 229 | ctx->pos = (ctx->pos & PART_MASK) | i; |
Martin Brandenburg | bf15ba7 | 2017-05-02 12:15:10 -0400 | [diff] [blame] | 230 | continue; |
| 231 | next: |
| 232 | i += 8; |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 233 | } |
| 234 | return 1; |
| 235 | } |
| 236 | |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 237 | static int orangefs_dir_fill(struct orangefs_inode_s *oi, |
| 238 | struct orangefs_dir *od, struct dentry *dentry, |
| 239 | struct dir_context *ctx) |
| 240 | { |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 241 | struct orangefs_dir_part *part; |
| 242 | size_t count; |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 243 | |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 244 | count = ((ctx->pos & PART_MASK) >> PART_SHIFT) - 1; |
| 245 | |
| 246 | part = od->part; |
| 247 | while (part->next && count) { |
| 248 | count--; |
| 249 | part = part->next; |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 250 | } |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 251 | /* This means the userspace file offset is invalid. */ |
| 252 | if (count) { |
| 253 | od->error = -EIO; |
| 254 | return -EIO; |
| 255 | } |
| 256 | |
| 257 | while (part && part->len) { |
| 258 | int r; |
| 259 | r = fill_from_part(part, ctx); |
| 260 | if (r < 0) { |
| 261 | od->error = r; |
| 262 | return r; |
| 263 | } else if (r == 0) { |
| 264 | /* Userspace buffer is full. */ |
| 265 | break; |
| 266 | } else { |
| 267 | /* |
| 268 | * The part ran out of data. Move to the next |
| 269 | * part. */ |
| 270 | ctx->pos = (ctx->pos & PART_MASK) + |
| 271 | (1 << PART_SHIFT); |
| 272 | part = part->next; |
| 273 | } |
| 274 | } |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 275 | return 0; |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 276 | } |
| 277 | |
Martin Brandenburg | 942835d | 2017-05-02 12:15:11 -0400 | [diff] [blame^] | 278 | static loff_t orangefs_dir_llseek(struct file *file, loff_t offset, |
| 279 | int whence) |
| 280 | { |
| 281 | struct orangefs_dir *od = file->private_data; |
| 282 | /* |
| 283 | * Delete the stored data so userspace sees new directory |
| 284 | * entries. |
| 285 | */ |
| 286 | if (!whence && offset < od->end) { |
| 287 | struct orangefs_dir_part *part = od->part; |
| 288 | while (part) { |
| 289 | struct orangefs_dir_part *next = part->next; |
| 290 | vfree(part); |
| 291 | part = next; |
| 292 | } |
| 293 | od->token = ORANGEFS_ITERATE_START; |
| 294 | od->part = NULL; |
| 295 | od->end = 1 << PART_SHIFT; |
| 296 | } |
| 297 | return default_llseek(file, offset, whence); |
| 298 | } |
| 299 | |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 300 | static int orangefs_dir_iterate(struct file *file, |
| 301 | struct dir_context *ctx) |
| 302 | { |
| 303 | struct orangefs_inode_s *oi; |
| 304 | struct orangefs_dir *od; |
| 305 | struct dentry *dentry; |
| 306 | int r; |
| 307 | |
| 308 | dentry = file->f_path.dentry; |
| 309 | oi = ORANGEFS_I(dentry->d_inode); |
| 310 | od = file->private_data; |
| 311 | |
| 312 | if (od->error) |
| 313 | return od->error; |
| 314 | |
| 315 | if (ctx->pos == 0) { |
| 316 | if (!dir_emit_dot(file, ctx)) |
| 317 | return 0; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 318 | ctx->pos++; |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 319 | } |
| 320 | if (ctx->pos == 1) { |
| 321 | if (!dir_emit_dotdot(file, ctx)) |
| 322 | return 0; |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 323 | ctx->pos = 1 << PART_SHIFT; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 324 | } |
| 325 | |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 326 | /* |
| 327 | * The seek position is in the first synthesized part but is not |
| 328 | * valid. |
| 329 | */ |
| 330 | if ((ctx->pos & PART_MASK) == 0) |
| 331 | return -EIO; |
| 332 | |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 333 | r = 0; |
| 334 | |
Martin Brandenburg | 72f66b8 | 2017-04-25 15:38:00 -0400 | [diff] [blame] | 335 | /* |
| 336 | * Must read more if the user has sought past what has been read |
| 337 | * so far. Stop a user who has sought past the end. |
| 338 | */ |
Martin Brandenburg | 7b796ae | 2017-04-25 15:38:02 -0400 | [diff] [blame] | 339 | while (od->token != ORANGEFS_ITERATE_END && |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 340 | ctx->pos > od->end) { |
Martin Brandenburg | 72f66b8 | 2017-04-25 15:38:00 -0400 | [diff] [blame] | 341 | r = orangefs_dir_more(oi, od, dentry); |
| 342 | if (r) |
| 343 | return r; |
| 344 | } |
Martin Brandenburg | 7b796ae | 2017-04-25 15:38:02 -0400 | [diff] [blame] | 345 | if (od->token == ORANGEFS_ITERATE_END && ctx->pos > od->end) |
Martin Brandenburg | 72f66b8 | 2017-04-25 15:38:00 -0400 | [diff] [blame] | 346 | return -EIO; |
Martin Brandenburg | 72f66b8 | 2017-04-25 15:38:00 -0400 | [diff] [blame] | 347 | |
| 348 | /* Then try to fill if there's any left in the buffer. */ |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 349 | if (ctx->pos < od->end) { |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 350 | r = orangefs_dir_fill(oi, od, dentry, ctx); |
| 351 | if (r) |
| 352 | return r; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 353 | } |
| 354 | |
Martin Brandenburg | 72f66b8 | 2017-04-25 15:38:00 -0400 | [diff] [blame] | 355 | /* Finally get some more and try to fill. */ |
Martin Brandenburg | 7b796ae | 2017-04-25 15:38:02 -0400 | [diff] [blame] | 356 | if (od->token != ORANGEFS_ITERATE_END) { |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 357 | r = orangefs_dir_more(oi, od, dentry); |
| 358 | if (r) |
| 359 | return r; |
| 360 | r = orangefs_dir_fill(oi, od, dentry, ctx); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 361 | } |
| 362 | |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 363 | return r; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 364 | } |
| 365 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 366 | static int orangefs_dir_open(struct inode *inode, struct file *file) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 367 | { |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 368 | struct orangefs_dir *od; |
| 369 | file->private_data = kmalloc(sizeof(struct orangefs_dir), |
| 370 | GFP_KERNEL); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 371 | if (!file->private_data) |
| 372 | return -ENOMEM; |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 373 | od = file->private_data; |
Martin Brandenburg | 7b796ae | 2017-04-25 15:38:02 -0400 | [diff] [blame] | 374 | od->token = ORANGEFS_ITERATE_START; |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 375 | od->part = NULL; |
| 376 | od->end = 1 << PART_SHIFT; |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 377 | od->error = 0; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 378 | return 0; |
| 379 | } |
| 380 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 381 | static int orangefs_dir_release(struct inode *inode, struct file *file) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 382 | { |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 383 | struct orangefs_dir *od = file->private_data; |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 384 | struct orangefs_dir_part *part = od->part; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 385 | orangefs_flush_inode(inode); |
Martin Brandenburg | 480e3e5 | 2017-04-25 15:38:01 -0400 | [diff] [blame] | 386 | while (part) { |
| 387 | struct orangefs_dir_part *next = part->next; |
| 388 | vfree(part); |
| 389 | part = next; |
| 390 | } |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 391 | kfree(od); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 392 | return 0; |
| 393 | } |
| 394 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 395 | const struct file_operations orangefs_dir_operations = { |
Martin Brandenburg | 942835d | 2017-05-02 12:15:11 -0400 | [diff] [blame^] | 396 | .llseek = orangefs_dir_llseek, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 397 | .read = generic_read_dir, |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 398 | .iterate = orangefs_dir_iterate, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 399 | .open = orangefs_dir_open, |
Martin Brandenburg | 382f458 | 2017-04-25 15:37:59 -0400 | [diff] [blame] | 400 | .release = orangefs_dir_release |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 401 | }; |