|
20 | 20 | cifs_dbg(VFS, fmt, ## __VA_ARGS__); \ |
21 | 21 | } while (0) |
22 | 22 |
|
| 23 | +static inline size_t cifs_io_align(struct fs_context *fc, |
| 24 | + const char *name, size_t size) |
| 25 | +{ |
| 26 | + if (!size || !IS_ALIGNED(size, PAGE_SIZE)) { |
| 27 | + cifs_errorf(fc, "unaligned %s, making it a multiple of %lu bytes\n", |
| 28 | + name, PAGE_SIZE); |
| 29 | + size = umax(round_down(size, PAGE_SIZE), PAGE_SIZE); |
| 30 | + } |
| 31 | + return size; |
| 32 | +} |
| 33 | + |
| 34 | +#define CIFS_ALIGN_WSIZE(_fc, _size) cifs_io_align(_fc, "wsize", _size) |
| 35 | +#define CIFS_ALIGN_RSIZE(_fc, _size) cifs_io_align(_fc, "rsize", _size) |
| 36 | +#define CIFS_ALIGN_BSIZE(_fc, _size) cifs_io_align(_fc, "bsize", _size) |
| 37 | + |
23 | 38 | enum smb_version { |
24 | 39 | Smb_1 = 1, |
25 | 40 | Smb_20, |
@@ -361,4 +376,36 @@ static inline void cifs_mount_unlock(void) |
361 | 376 | mutex_unlock(&cifs_mount_mutex); |
362 | 377 | } |
363 | 378 |
|
| 379 | +static inline void cifs_negotiate_rsize(struct TCP_Server_Info *server, |
| 380 | + struct smb3_fs_context *ctx, |
| 381 | + struct cifs_tcon *tcon) |
| 382 | +{ |
| 383 | + unsigned int size; |
| 384 | + |
| 385 | + size = umax(server->ops->negotiate_rsize(tcon, ctx), PAGE_SIZE); |
| 386 | + if (ctx->rsize) |
| 387 | + size = umax(umin(ctx->rsize, size), PAGE_SIZE); |
| 388 | + ctx->rsize = round_down(size, PAGE_SIZE); |
| 389 | +} |
| 390 | + |
| 391 | +static inline void cifs_negotiate_wsize(struct TCP_Server_Info *server, |
| 392 | + struct smb3_fs_context *ctx, |
| 393 | + struct cifs_tcon *tcon) |
| 394 | +{ |
| 395 | + unsigned int size; |
| 396 | + |
| 397 | + size = umax(server->ops->negotiate_wsize(tcon, ctx), PAGE_SIZE); |
| 398 | + if (ctx->wsize) |
| 399 | + size = umax(umin(ctx->wsize, size), PAGE_SIZE); |
| 400 | + ctx->wsize = round_down(size, PAGE_SIZE); |
| 401 | +} |
| 402 | + |
| 403 | +static inline void cifs_negotiate_iosize(struct TCP_Server_Info *server, |
| 404 | + struct smb3_fs_context *ctx, |
| 405 | + struct cifs_tcon *tcon) |
| 406 | +{ |
| 407 | + cifs_negotiate_rsize(server, ctx, tcon); |
| 408 | + cifs_negotiate_wsize(server, ctx, tcon); |
| 409 | +} |
| 410 | + |
364 | 411 | #endif |
0 commit comments