diff options
Diffstat (limited to 'fs')
51 files changed, 766 insertions, 598 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index e3ff2b9e602f..33b7235f853b 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c | |||
@@ -1208,9 +1208,11 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma, | |||
1208 | * check for an ELF header. If we find one, dump the first page to | 1208 | * check for an ELF header. If we find one, dump the first page to |
1209 | * aid in determining what was mapped here. | 1209 | * aid in determining what was mapped here. |
1210 | */ | 1210 | */ |
1211 | if (FILTER(ELF_HEADERS) && vma->vm_file != NULL && vma->vm_pgoff == 0) { | 1211 | if (FILTER(ELF_HEADERS) && |
1212 | vma->vm_pgoff == 0 && (vma->vm_flags & VM_READ)) { | ||
1212 | u32 __user *header = (u32 __user *) vma->vm_start; | 1213 | u32 __user *header = (u32 __user *) vma->vm_start; |
1213 | u32 word; | 1214 | u32 word; |
1215 | mm_segment_t fs = get_fs(); | ||
1214 | /* | 1216 | /* |
1215 | * Doing it this way gets the constant folded by GCC. | 1217 | * Doing it this way gets the constant folded by GCC. |
1216 | */ | 1218 | */ |
@@ -1223,7 +1225,15 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma, | |||
1223 | magic.elfmag[EI_MAG1] = ELFMAG1; | 1225 | magic.elfmag[EI_MAG1] = ELFMAG1; |
1224 | magic.elfmag[EI_MAG2] = ELFMAG2; | 1226 | magic.elfmag[EI_MAG2] = ELFMAG2; |
1225 | magic.elfmag[EI_MAG3] = ELFMAG3; | 1227 | magic.elfmag[EI_MAG3] = ELFMAG3; |
1226 | if (get_user(word, header) == 0 && word == magic.cmp) | 1228 | /* |
1229 | * Switch to the user "segment" for get_user(), | ||
1230 | * then put back what elf_core_dump() had in place. | ||
1231 | */ | ||
1232 | set_fs(USER_DS); | ||
1233 | if (unlikely(get_user(word, header))) | ||
1234 | word = 0; | ||
1235 | set_fs(fs); | ||
1236 | if (word == magic.cmp) | ||
1227 | return PAGE_SIZE; | 1237 | return PAGE_SIZE; |
1228 | } | 1238 | } |
1229 | 1239 | ||
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c index 77ebc3c263d6..549b0144da11 100644 --- a/fs/bio-integrity.c +++ b/fs/bio-integrity.c | |||
@@ -140,7 +140,6 @@ int bio_integrity_add_page(struct bio *bio, struct page *page, | |||
140 | 140 | ||
141 | iv = bip_vec_idx(bip, bip->bip_vcnt); | 141 | iv = bip_vec_idx(bip, bip->bip_vcnt); |
142 | BUG_ON(iv == NULL); | 142 | BUG_ON(iv == NULL); |
143 | BUG_ON(iv->bv_page != NULL); | ||
144 | 143 | ||
145 | iv->bv_page = page; | 144 | iv->bv_page = page; |
146 | iv->bv_len = len; | 145 | iv->bv_len = len; |
@@ -465,7 +464,7 @@ static int bio_integrity_verify(struct bio *bio) | |||
465 | 464 | ||
466 | if (ret) { | 465 | if (ret) { |
467 | kunmap_atomic(kaddr, KM_USER0); | 466 | kunmap_atomic(kaddr, KM_USER0); |
468 | break; | 467 | return ret; |
469 | } | 468 | } |
470 | 469 | ||
471 | sectors = bv->bv_len / bi->sector_size; | 470 | sectors = bv->bv_len / bi->sector_size; |
@@ -493,18 +492,13 @@ static void bio_integrity_verify_fn(struct work_struct *work) | |||
493 | struct bio_integrity_payload *bip = | 492 | struct bio_integrity_payload *bip = |
494 | container_of(work, struct bio_integrity_payload, bip_work); | 493 | container_of(work, struct bio_integrity_payload, bip_work); |
495 | struct bio *bio = bip->bip_bio; | 494 | struct bio *bio = bip->bip_bio; |
496 | int error = bip->bip_error; | 495 | int error; |
497 | 496 | ||
498 | if (bio_integrity_verify(bio)) { | 497 | error = bio_integrity_verify(bio); |
499 | clear_bit(BIO_UPTODATE, &bio->bi_flags); | ||
500 | error = -EIO; | ||
501 | } | ||
502 | 498 | ||
503 | /* Restore original bio completion handler */ | 499 | /* Restore original bio completion handler */ |
504 | bio->bi_end_io = bip->bip_end_io; | 500 | bio->bi_end_io = bip->bip_end_io; |
505 | 501 | bio_endio(bio, error); | |
506 | if (bio->bi_end_io) | ||
507 | bio->bi_end_io(bio, error); | ||
508 | } | 502 | } |
509 | 503 | ||
510 | /** | 504 | /** |
@@ -525,7 +519,17 @@ void bio_integrity_endio(struct bio *bio, int error) | |||
525 | 519 | ||
526 | BUG_ON(bip->bip_bio != bio); | 520 | BUG_ON(bip->bip_bio != bio); |
527 | 521 | ||
528 | bip->bip_error = error; | 522 | /* In case of an I/O error there is no point in verifying the |
523 | * integrity metadata. Restore original bio end_io handler | ||
524 | * and run it. | ||
525 | */ | ||
526 | if (error) { | ||
527 | bio->bi_end_io = bip->bip_end_io; | ||
528 | bio_endio(bio, error); | ||
529 | |||
530 | return; | ||
531 | } | ||
532 | |||
529 | INIT_WORK(&bip->bip_work, bio_integrity_verify_fn); | 533 | INIT_WORK(&bip->bip_work, bio_integrity_verify_fn); |
530 | queue_work(kintegrityd_wq, &bip->bip_work); | 534 | queue_work(kintegrityd_wq, &bip->bip_work); |
531 | } | 535 | } |
diff --git a/fs/buffer.c b/fs/buffer.c index b58208f1640a..665d446b25bc 100644 --- a/fs/buffer.c +++ b/fs/buffer.c | |||
@@ -2688,7 +2688,7 @@ int nobh_write_end(struct file *file, struct address_space *mapping, | |||
2688 | struct buffer_head *bh; | 2688 | struct buffer_head *bh; |
2689 | BUG_ON(fsdata != NULL && page_has_buffers(page)); | 2689 | BUG_ON(fsdata != NULL && page_has_buffers(page)); |
2690 | 2690 | ||
2691 | if (unlikely(copied < len) && !page_has_buffers(page)) | 2691 | if (unlikely(copied < len) && head) |
2692 | attach_nobh_buffers(page, head); | 2692 | attach_nobh_buffers(page, head); |
2693 | if (page_has_buffers(page)) | 2693 | if (page_has_buffers(page)) |
2694 | return generic_write_end(file, mapping, pos, len, | 2694 | return generic_write_end(file, mapping, pos, len, |
diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES index 080703a15f44..73ac7ebd1dfc 100644 --- a/fs/cifs/CHANGES +++ b/fs/cifs/CHANGES | |||
@@ -5,7 +5,9 @@ rather than posix (advisory) byte range locks, even though server would | |||
5 | support posix byte range locks. Fix query of root inode when prefixpath | 5 | support posix byte range locks. Fix query of root inode when prefixpath |
6 | specified and user does not have access to query information about the | 6 | specified and user does not have access to query information about the |
7 | top of the share. Fix problem in 2.6.28 resolving DFS paths to | 7 | top of the share. Fix problem in 2.6.28 resolving DFS paths to |
8 | Samba servers (worked to Windows). | 8 | Samba servers (worked to Windows). Fix rmdir so that pending search |
9 | (readdir) requests do not get invalid results which include the now | ||
10 | removed directory. | ||
9 | 11 | ||
10 | Version 1.55 | 12 | Version 1.55 |
11 | ------------ | 13 | ------------ |
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index d4839cf0cb2c..7c9809523f42 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c | |||
@@ -48,11 +48,11 @@ static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu, | |||
48 | if ((cifs_pdu == NULL) || (signature == NULL) || (key == NULL)) | 48 | if ((cifs_pdu == NULL) || (signature == NULL) || (key == NULL)) |
49 | return -EINVAL; | 49 | return -EINVAL; |
50 | 50 | ||
51 | MD5Init(&context); | 51 | cifs_MD5_init(&context); |
52 | MD5Update(&context, (char *)&key->data, key->len); | 52 | cifs_MD5_update(&context, (char *)&key->data, key->len); |
53 | MD5Update(&context, cifs_pdu->Protocol, cifs_pdu->smb_buf_length); | 53 | cifs_MD5_update(&context, cifs_pdu->Protocol, cifs_pdu->smb_buf_length); |
54 | 54 | ||
55 | MD5Final(signature, &context); | 55 | cifs_MD5_final(signature, &context); |
56 | return 0; | 56 | return 0; |
57 | } | 57 | } |
58 | 58 | ||
@@ -96,8 +96,8 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec, | |||
96 | if ((iov == NULL) || (signature == NULL) || (key == NULL)) | 96 | if ((iov == NULL) || (signature == NULL) || (key == NULL)) |
97 | return -EINVAL; | 97 | return -EINVAL; |
98 | 98 | ||
99 | MD5Init(&context); | 99 | cifs_MD5_init(&context); |
100 | MD5Update(&context, (char *)&key->data, key->len); | 100 | cifs_MD5_update(&context, (char *)&key->data, key->len); |
101 | for (i = 0; i < n_vec; i++) { | 101 | for (i = 0; i < n_vec; i++) { |
102 | if (iov[i].iov_len == 0) | 102 | if (iov[i].iov_len == 0) |
103 | continue; | 103 | continue; |
@@ -110,13 +110,13 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec, | |||
110 | if (i == 0) { | 110 | if (i == 0) { |
111 | if (iov[0].iov_len <= 8) /* cmd field at offset 9 */ | 111 | if (iov[0].iov_len <= 8) /* cmd field at offset 9 */ |
112 | break; /* nothing to sign or corrupt header */ | 112 | break; /* nothing to sign or corrupt header */ |
113 | MD5Update(&context, iov[0].iov_base+4, | 113 | cifs_MD5_update(&context, iov[0].iov_base+4, |
114 | iov[0].iov_len-4); | 114 | iov[0].iov_len-4); |
115 | } else | 115 | } else |
116 | MD5Update(&context, iov[i].iov_base, iov[i].iov_len); | 116 | cifs_MD5_update(&context, iov[i].iov_base, iov[i].iov_len); |
117 | } | 117 | } |
118 | 118 | ||
119 | MD5Final(signature, &context); | 119 | cifs_MD5_final(signature, &context); |
120 | 120 | ||
121 | return 0; | 121 | return 0; |
122 | } | 122 | } |
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 06f6779988bf..382ba6298809 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h | |||
@@ -35,8 +35,8 @@ extern struct smb_hdr *cifs_buf_get(void); | |||
35 | extern void cifs_buf_release(void *); | 35 | extern void cifs_buf_release(void *); |
36 | extern struct smb_hdr *cifs_small_buf_get(void); | 36 | extern struct smb_hdr *cifs_small_buf_get(void); |
37 | extern void cifs_small_buf_release(void *); | 37 | extern void cifs_small_buf_release(void *); |
38 | extern int smb_send(struct socket *, struct smb_hdr *, | 38 | extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *, |
39 | unsigned int /* length */ , struct sockaddr *, bool); | 39 | unsigned int /* length */); |
40 | extern unsigned int _GetXid(void); | 40 | extern unsigned int _GetXid(void); |
41 | extern void _FreeXid(unsigned int); | 41 | extern void _FreeXid(unsigned int); |
42 | #define GetXid() (int)_GetXid(); cFYI(1,("CIFS VFS: in %s as Xid: %d with uid: %d",__func__, xid,current_fsuid())); | 42 | #define GetXid() (int)_GetXid(); cFYI(1,("CIFS VFS: in %s as Xid: %d with uid: %d",__func__, xid,current_fsuid())); |
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index e9ea394ee075..2209be943051 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -1354,7 +1354,7 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
1354 | } | 1354 | } |
1355 | 1355 | ||
1356 | static struct TCP_Server_Info * | 1356 | static struct TCP_Server_Info * |
1357 | cifs_find_tcp_session(struct sockaddr *addr) | 1357 | cifs_find_tcp_session(struct sockaddr_storage *addr) |
1358 | { | 1358 | { |
1359 | struct list_head *tmp; | 1359 | struct list_head *tmp; |
1360 | struct TCP_Server_Info *server; | 1360 | struct TCP_Server_Info *server; |
@@ -1374,11 +1374,11 @@ cifs_find_tcp_session(struct sockaddr *addr) | |||
1374 | if (server->tcpStatus == CifsNew) | 1374 | if (server->tcpStatus == CifsNew) |
1375 | continue; | 1375 | continue; |
1376 | 1376 | ||
1377 | if (addr->sa_family == AF_INET && | 1377 | if (addr->ss_family == AF_INET && |
1378 | (addr4->sin_addr.s_addr != | 1378 | (addr4->sin_addr.s_addr != |
1379 | server->addr.sockAddr.sin_addr.s_addr)) | 1379 | server->addr.sockAddr.sin_addr.s_addr)) |
1380 | continue; | 1380 | continue; |
1381 | else if (addr->sa_family == AF_INET6 && | 1381 | else if (addr->ss_family == AF_INET6 && |
1382 | memcmp(&server->addr.sockAddr6.sin6_addr, | 1382 | memcmp(&server->addr.sockAddr6.sin6_addr, |
1383 | &addr6->sin6_addr, sizeof(addr6->sin6_addr))) | 1383 | &addr6->sin6_addr, sizeof(addr6->sin6_addr))) |
1384 | continue; | 1384 | continue; |
@@ -1419,12 +1419,12 @@ static struct TCP_Server_Info * | |||
1419 | cifs_get_tcp_session(struct smb_vol *volume_info) | 1419 | cifs_get_tcp_session(struct smb_vol *volume_info) |
1420 | { | 1420 | { |
1421 | struct TCP_Server_Info *tcp_ses = NULL; | 1421 | struct TCP_Server_Info *tcp_ses = NULL; |
1422 | struct sockaddr addr; | 1422 | struct sockaddr_storage addr; |
1423 | struct sockaddr_in *sin_server = (struct sockaddr_in *) &addr; | 1423 | struct sockaddr_in *sin_server = (struct sockaddr_in *) &addr; |
1424 | struct sockaddr_in6 *sin_server6 = (struct sockaddr_in6 *) &addr; | 1424 | struct sockaddr_in6 *sin_server6 = (struct sockaddr_in6 *) &addr; |
1425 | int rc; | 1425 | int rc; |
1426 | 1426 | ||
1427 | memset(&addr, 0, sizeof(struct sockaddr)); | 1427 | memset(&addr, 0, sizeof(struct sockaddr_storage)); |
1428 | 1428 | ||
1429 | if (volume_info->UNCip && volume_info->UNC) { | 1429 | if (volume_info->UNCip && volume_info->UNC) { |
1430 | rc = cifs_inet_pton(AF_INET, volume_info->UNCip, | 1430 | rc = cifs_inet_pton(AF_INET, volume_info->UNCip, |
@@ -1435,9 +1435,9 @@ cifs_get_tcp_session(struct smb_vol *volume_info) | |||
1435 | rc = cifs_inet_pton(AF_INET6, volume_info->UNCip, | 1435 | rc = cifs_inet_pton(AF_INET6, volume_info->UNCip, |
1436 | &sin_server6->sin6_addr.in6_u); | 1436 | &sin_server6->sin6_addr.in6_u); |
1437 | if (rc > 0) | 1437 | if (rc > 0) |
1438 | addr.sa_family = AF_INET6; | 1438 | addr.ss_family = AF_INET6; |
1439 | } else { | 1439 | } else { |
1440 | addr.sa_family = AF_INET; | 1440 | addr.ss_family = AF_INET; |
1441 | } | 1441 | } |
1442 | 1442 | ||
1443 | if (rc <= 0) { | 1443 | if (rc <= 0) { |
@@ -1502,7 +1502,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) | |||
1502 | tcp_ses->tcpStatus = CifsNew; | 1502 | tcp_ses->tcpStatus = CifsNew; |
1503 | ++tcp_ses->srv_count; | 1503 | ++tcp_ses->srv_count; |
1504 | 1504 | ||
1505 | if (addr.sa_family == AF_INET6) { | 1505 | if (addr.ss_family == AF_INET6) { |
1506 | cFYI(1, ("attempting ipv6 connect")); | 1506 | cFYI(1, ("attempting ipv6 connect")); |
1507 | /* BB should we allow ipv6 on port 139? */ | 1507 | /* BB should we allow ipv6 on port 139? */ |
1508 | /* other OS never observed in Wild doing 139 with v6 */ | 1508 | /* other OS never observed in Wild doing 139 with v6 */ |
@@ -1802,7 +1802,7 @@ ipv4_connect(struct TCP_Server_Info *server) | |||
1802 | * user space buffer | 1802 | * user space buffer |
1803 | */ | 1803 | */ |
1804 | socket->sk->sk_rcvtimeo = 7 * HZ; | 1804 | socket->sk->sk_rcvtimeo = 7 * HZ; |
1805 | socket->sk->sk_sndtimeo = 3 * HZ; | 1805 | socket->sk->sk_sndtimeo = 5 * HZ; |
1806 | 1806 | ||
1807 | /* make the bufsizes depend on wsize/rsize and max requests */ | 1807 | /* make the bufsizes depend on wsize/rsize and max requests */ |
1808 | if (server->noautotune) { | 1808 | if (server->noautotune) { |
@@ -1860,9 +1860,7 @@ ipv4_connect(struct TCP_Server_Info *server) | |||
1860 | smb_buf = (struct smb_hdr *)ses_init_buf; | 1860 | smb_buf = (struct smb_hdr *)ses_init_buf; |
1861 | /* sizeof RFC1002_SESSION_REQUEST with no scope */ | 1861 | /* sizeof RFC1002_SESSION_REQUEST with no scope */ |
1862 | smb_buf->smb_buf_length = 0x81000044; | 1862 | smb_buf->smb_buf_length = 0x81000044; |
1863 | rc = smb_send(socket, smb_buf, 0x44, | 1863 | rc = smb_send(server, smb_buf, 0x44); |
1864 | (struct sockaddr *) &server->addr.sockAddr, | ||
1865 | server->noblocksnd); | ||
1866 | kfree(ses_init_buf); | 1864 | kfree(ses_init_buf); |
1867 | msleep(1); /* RFC1001 layer in at least one server | 1865 | msleep(1); /* RFC1001 layer in at least one server |
1868 | requires very short break before negprot | 1866 | requires very short break before negprot |
@@ -1955,7 +1953,7 @@ ipv6_connect(struct TCP_Server_Info *server) | |||
1955 | * user space buffer | 1953 | * user space buffer |
1956 | */ | 1954 | */ |
1957 | socket->sk->sk_rcvtimeo = 7 * HZ; | 1955 | socket->sk->sk_rcvtimeo = 7 * HZ; |
1958 | socket->sk->sk_sndtimeo = 3 * HZ; | 1956 | socket->sk->sk_sndtimeo = 5 * HZ; |
1959 | server->ssocket = socket; | 1957 | server->ssocket = socket; |
1960 | 1958 | ||
1961 | return rc; | 1959 | return rc; |
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 838d9c720a5c..964aad03c5ad 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c | |||
@@ -129,6 +129,17 @@ cifs_bp_rename_retry: | |||
129 | return full_path; | 129 | return full_path; |
130 | } | 130 | } |
131 | 131 | ||
132 | static void setup_cifs_dentry(struct cifsTconInfo *tcon, | ||
133 | struct dentry *direntry, | ||
134 | struct inode *newinode) | ||
135 | { | ||
136 | if (tcon->nocase) | ||
137 | direntry->d_op = &cifs_ci_dentry_ops; | ||
138 | else | ||
139 | direntry->d_op = &cifs_dentry_ops; | ||
140 | d_instantiate(direntry, newinode); | ||
141 | } | ||
142 | |||
132 | /* Inode operations in similar order to how they appear in Linux file fs.h */ | 143 | /* Inode operations in similar order to how they appear in Linux file fs.h */ |
133 | 144 | ||
134 | int | 145 | int |
@@ -139,14 +150,14 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
139 | int xid; | 150 | int xid; |
140 | int create_options = CREATE_NOT_DIR; | 151 | int create_options = CREATE_NOT_DIR; |
141 | int oplock = 0; | 152 | int oplock = 0; |
153 | /* BB below access is too much for the mknod to request */ | ||
142 | int desiredAccess = GENERIC_READ | GENERIC_WRITE; | 154 | int desiredAccess = GENERIC_READ | GENERIC_WRITE; |
143 | __u16 fileHandle; | 155 | __u16 fileHandle; |
144 | struct cifs_sb_info *cifs_sb; | 156 | struct cifs_sb_info *cifs_sb; |
145 | struct cifsTconInfo *pTcon; | 157 | struct cifsTconInfo *tcon; |
146 | char *full_path = NULL; | 158 | char *full_path = NULL; |
147 | FILE_ALL_INFO *buf = NULL; | 159 | FILE_ALL_INFO *buf = NULL; |
148 | struct inode *newinode = NULL; | 160 | struct inode *newinode = NULL; |
149 | struct cifsFileInfo *pCifsFile = NULL; | ||
150 | struct cifsInodeInfo *pCifsInode; | 161 | struct cifsInodeInfo *pCifsInode; |
151 | int disposition = FILE_OVERWRITE_IF; | 162 | int disposition = FILE_OVERWRITE_IF; |
152 | bool write_only = false; | 163 | bool write_only = false; |
@@ -154,7 +165,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
154 | xid = GetXid(); | 165 | xid = GetXid(); |
155 | 166 | ||
156 | cifs_sb = CIFS_SB(inode->i_sb); | 167 | cifs_sb = CIFS_SB(inode->i_sb); |
157 | pTcon = cifs_sb->tcon; | 168 | tcon = cifs_sb->tcon; |
158 | 169 | ||
159 | full_path = build_path_from_dentry(direntry); | 170 | full_path = build_path_from_dentry(direntry); |
160 | if (full_path == NULL) { | 171 | if (full_path == NULL) { |
@@ -162,6 +173,8 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
162 | return -ENOMEM; | 173 | return -ENOMEM; |
163 | } | 174 | } |
164 | 175 | ||
176 | mode &= ~current->fs->umask; | ||
177 | |||
165 | if (nd && (nd->flags & LOOKUP_OPEN)) { | 178 | if (nd && (nd->flags & LOOKUP_OPEN)) { |
166 | int oflags = nd->intent.open.flags; | 179 | int oflags = nd->intent.open.flags; |
167 | 180 | ||
@@ -196,17 +209,15 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
196 | return -ENOMEM; | 209 | return -ENOMEM; |
197 | } | 210 | } |
198 | 211 | ||
199 | mode &= ~current->fs->umask; | ||
200 | |||
201 | /* | 212 | /* |
202 | * if we're not using unix extensions, see if we need to set | 213 | * if we're not using unix extensions, see if we need to set |
203 | * ATTR_READONLY on the create call | 214 | * ATTR_READONLY on the create call |
204 | */ | 215 | */ |
205 | if (!pTcon->unix_ext && (mode & S_IWUGO) == 0) | 216 | if (!tcon->unix_ext && (mode & S_IWUGO) == 0) |
206 | create_options |= CREATE_OPTION_READONLY; | 217 | create_options |= CREATE_OPTION_READONLY; |
207 | 218 | ||
208 | if (cifs_sb->tcon->ses->capabilities & CAP_NT_SMBS) | 219 | if (cifs_sb->tcon->ses->capabilities & CAP_NT_SMBS) |
209 | rc = CIFSSMBOpen(xid, pTcon, full_path, disposition, | 220 | rc = CIFSSMBOpen(xid, tcon, full_path, disposition, |
210 | desiredAccess, create_options, | 221 | desiredAccess, create_options, |
211 | &fileHandle, &oplock, buf, cifs_sb->local_nls, | 222 | &fileHandle, &oplock, buf, cifs_sb->local_nls, |
212 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 223 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
@@ -215,7 +226,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
215 | 226 | ||
216 | if (rc == -EIO) { | 227 | if (rc == -EIO) { |
217 | /* old server, retry the open legacy style */ | 228 | /* old server, retry the open legacy style */ |
218 | rc = SMBLegacyOpen(xid, pTcon, full_path, disposition, | 229 | rc = SMBLegacyOpen(xid, tcon, full_path, disposition, |
219 | desiredAccess, create_options, | 230 | desiredAccess, create_options, |
220 | &fileHandle, &oplock, buf, cifs_sb->local_nls, | 231 | &fileHandle, &oplock, buf, cifs_sb->local_nls, |
221 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 232 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
@@ -225,7 +236,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
225 | } else { | 236 | } else { |
226 | /* If Open reported that we actually created a file | 237 | /* If Open reported that we actually created a file |
227 | then we now have to set the mode if possible */ | 238 | then we now have to set the mode if possible */ |
228 | if ((pTcon->unix_ext) && (oplock & CIFS_CREATE_ACTION)) { | 239 | if ((tcon->unix_ext) && (oplock & CIFS_CREATE_ACTION)) { |
229 | struct cifs_unix_set_info_args args = { | 240 | struct cifs_unix_set_info_args args = { |
230 | .mode = mode, | 241 | .mode = mode, |
231 | .ctime = NO_CHANGE_64, | 242 | .ctime = NO_CHANGE_64, |
@@ -244,20 +255,20 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
244 | args.uid = NO_CHANGE_64; | 255 | args.uid = NO_CHANGE_64; |
245 | args.gid = NO_CHANGE_64; | 256 | args.gid = NO_CHANGE_64; |
246 | } | 257 | } |
247 | CIFSSMBUnixSetInfo(xid, pTcon, full_path, &args, | 258 | CIFSSMBUnixSetInfo(xid, tcon, full_path, &args, |
248 | cifs_sb->local_nls, | 259 | cifs_sb->local_nls, |
249 | cifs_sb->mnt_cifs_flags & | 260 | cifs_sb->mnt_cifs_flags & |
250 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 261 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
251 | } else { | 262 | } else { |
252 | /* BB implement mode setting via Windows security | 263 | /* BB implement mode setting via Windows security |
253 | descriptors e.g. */ | 264 | descriptors e.g. */ |
254 | /* CIFSSMBWinSetPerms(xid,pTcon,path,mode,-1,-1,nls);*/ | 265 | /* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/ |
255 | 266 | ||
256 | /* Could set r/o dos attribute if mode & 0222 == 0 */ | 267 | /* Could set r/o dos attribute if mode & 0222 == 0 */ |
257 | } | 268 | } |
258 | 269 | ||
259 | /* server might mask mode so we have to query for it */ | 270 | /* server might mask mode so we have to query for it */ |
260 | if (pTcon->unix_ext) | 271 | if (tcon->unix_ext) |
261 | rc = cifs_get_inode_info_unix(&newinode, full_path, | 272 | rc = cifs_get_inode_info_unix(&newinode, full_path, |
262 | inode->i_sb, xid); | 273 | inode->i_sb, xid); |
263 | else { | 274 | else { |
@@ -283,22 +294,17 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
283 | } | 294 | } |
284 | 295 | ||
285 | if (rc != 0) { | 296 | if (rc != 0) { |
286 | cFYI(1, | 297 | cFYI(1, ("Create worked, get_inode_info failed rc = %d", |
287 | ("Create worked but get_inode_info failed rc = %d", | 298 | rc)); |
288 | rc)); | 299 | } else |
289 | } else { | 300 | setup_cifs_dentry(tcon, direntry, newinode); |
290 | if (pTcon->nocase) | 301 | |
291 | direntry->d_op = &cifs_ci_dentry_ops; | ||
292 | else | ||
293 | direntry->d_op = &cifs_dentry_ops; | ||
294 | d_instantiate(direntry, newinode); | ||
295 | } | ||
296 | if ((nd == NULL /* nfsd case - nfs srv does not set nd */) || | 302 | if ((nd == NULL /* nfsd case - nfs srv does not set nd */) || |
297 | (!(nd->flags & LOOKUP_OPEN))) { | 303 | (!(nd->flags & LOOKUP_OPEN))) { |
298 | /* mknod case - do not leave file open */ | 304 | /* mknod case - do not leave file open */ |
299 | CIFSSMBClose(xid, pTcon, fileHandle); | 305 | CIFSSMBClose(xid, tcon, fileHandle); |
300 | } else if (newinode) { | 306 | } else if (newinode) { |
301 | pCifsFile = | 307 | struct cifsFileInfo *pCifsFile = |
302 | kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); | 308 | kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); |
303 | 309 | ||
304 | if (pCifsFile == NULL) | 310 | if (pCifsFile == NULL) |
@@ -316,7 +322,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
316 | /* set the following in open now | 322 | /* set the following in open now |
317 | pCifsFile->pfile = file; */ | 323 | pCifsFile->pfile = file; */ |
318 | write_lock(&GlobalSMBSeslock); | 324 | write_lock(&GlobalSMBSeslock); |
319 | list_add(&pCifsFile->tlist, &pTcon->openFileList); | 325 | list_add(&pCifsFile->tlist, &tcon->openFileList); |
320 | pCifsInode = CIFS_I(newinode); | 326 | pCifsInode = CIFS_I(newinode); |
321 | if (pCifsInode) { | 327 | if (pCifsInode) { |
322 | /* if readable file instance put first in list*/ | 328 | /* if readable file instance put first in list*/ |
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 5ab9896fdcb2..bcf7b5184664 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c | |||
@@ -1285,6 +1285,11 @@ int cifs_rmdir(struct inode *inode, struct dentry *direntry) | |||
1285 | cifsInode = CIFS_I(direntry->d_inode); | 1285 | cifsInode = CIFS_I(direntry->d_inode); |
1286 | cifsInode->time = 0; /* force revalidate to go get info when | 1286 | cifsInode->time = 0; /* force revalidate to go get info when |
1287 | needed */ | 1287 | needed */ |
1288 | |||
1289 | cifsInode = CIFS_I(inode); | ||
1290 | cifsInode->time = 0; /* force revalidate to get parent dir info | ||
1291 | since cached search results now invalid */ | ||
1292 | |||
1288 | direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime = | 1293 | direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime = |
1289 | current_fs_time(inode->i_sb); | 1294 | current_fs_time(inode->i_sb); |
1290 | 1295 | ||
diff --git a/fs/cifs/md5.c b/fs/cifs/md5.c index 462bbfefd4b6..98b66a54c319 100644 --- a/fs/cifs/md5.c +++ b/fs/cifs/md5.c | |||
@@ -10,8 +10,8 @@ | |||
10 | * with every copy. | 10 | * with every copy. |
11 | * | 11 | * |
12 | * To compute the message digest of a chunk of bytes, declare an | 12 | * To compute the message digest of a chunk of bytes, declare an |
13 | * MD5Context structure, pass it to MD5Init, call MD5Update as | 13 | * MD5Context structure, pass it to cifs_MD5_init, call cifs_MD5_update as |
14 | * needed on buffers full of bytes, and then call MD5Final, which | 14 | * needed on buffers full of bytes, and then call cifs_MD5_final, which |
15 | * will fill a supplied 16-byte array with the digest. | 15 | * will fill a supplied 16-byte array with the digest. |
16 | */ | 16 | */ |
17 | 17 | ||
@@ -45,7 +45,7 @@ byteReverse(unsigned char *buf, unsigned longs) | |||
45 | * initialization constants. | 45 | * initialization constants. |
46 | */ | 46 | */ |
47 | void | 47 | void |
48 | MD5Init(struct MD5Context *ctx) | 48 | cifs_MD5_init(struct MD5Context *ctx) |
49 | { | 49 | { |
50 | ctx->buf[0] = 0x67452301; | 50 | ctx->buf[0] = 0x67452301; |
51 | ctx->buf[1] = 0xefcdab89; | 51 | ctx->buf[1] = 0xefcdab89; |
@@ -61,7 +61,7 @@ MD5Init(struct MD5Context *ctx) | |||
61 | * of bytes. | 61 | * of bytes. |
62 | */ | 62 | */ |
63 | void | 63 | void |
64 | MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) | 64 | cifs_MD5_update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) |
65 | { | 65 | { |
66 | register __u32 t; | 66 | register __u32 t; |
67 | 67 | ||
@@ -110,7 +110,7 @@ MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) | |||
110 | * 1 0* (64-bit count of bits processed, MSB-first) | 110 | * 1 0* (64-bit count of bits processed, MSB-first) |
111 | */ | 111 | */ |
112 | void | 112 | void |
113 | MD5Final(unsigned char digest[16], struct MD5Context *ctx) | 113 | cifs_MD5_final(unsigned char digest[16], struct MD5Context *ctx) |
114 | { | 114 | { |
115 | unsigned int count; | 115 | unsigned int count; |
116 | unsigned char *p; | 116 | unsigned char *p; |
@@ -165,7 +165,7 @@ MD5Final(unsigned char digest[16], struct MD5Context *ctx) | |||
165 | 165 | ||
166 | /* | 166 | /* |
167 | * The core of the MD5 algorithm, this alters an existing MD5 hash to | 167 | * The core of the MD5 algorithm, this alters an existing MD5 hash to |
168 | * reflect the addition of 16 longwords of new data. MD5Update blocks | 168 | * reflect the addition of 16 longwords of new data. cifs_MD5_update blocks |
169 | * the data and converts bytes into longwords for this routine. | 169 | * the data and converts bytes into longwords for this routine. |
170 | */ | 170 | */ |
171 | static void | 171 | static void |
@@ -267,9 +267,9 @@ hmac_md5_init_rfc2104(unsigned char *key, int key_len, | |||
267 | unsigned char tk[16]; | 267 | unsigned char tk[16]; |
268 | struct MD5Context tctx; | 268 | struct MD5Context tctx; |
269 | 269 | ||
270 | MD5Init(&tctx); | 270 | cifs_MD5_init(&tctx); |
271 | MD5Update(&tctx, key, key_len); | 271 | cifs_MD5_update(&tctx, key, key_len); |
272 | MD5Final(tk, &tctx); | 272 | cifs_MD5_final(tk, &tctx); |
273 | 273 | ||
274 | key = tk; | 274 | key = tk; |
275 | key_len = 16; | 275 | key_len = 16; |
@@ -287,8 +287,8 @@ hmac_md5_init_rfc2104(unsigned char *key, int key_len, | |||
287 | ctx->k_opad[i] ^= 0x5c; | 287 | ctx->k_opad[i] ^= 0x5c; |
288 | } | 288 | } |
289 | 289 | ||
290 | MD5Init(&ctx->ctx); | 290 | cifs_MD5_init(&ctx->ctx); |
291 | MD5Update(&ctx->ctx, ctx->k_ipad, 64); | 291 | cifs_MD5_update(&ctx->ctx, ctx->k_ipad, 64); |
292 | } | 292 | } |
293 | #endif | 293 | #endif |
294 | 294 | ||
@@ -317,8 +317,8 @@ hmac_md5_init_limK_to_64(const unsigned char *key, int key_len, | |||
317 | ctx->k_opad[i] ^= 0x5c; | 317 | ctx->k_opad[i] ^= 0x5c; |
318 | } | 318 | } |
319 | 319 | ||
320 | MD5Init(&ctx->ctx); | 320 | cifs_MD5_init(&ctx->ctx); |
321 | MD5Update(&ctx->ctx, ctx->k_ipad, 64); | 321 | cifs_MD5_update(&ctx->ctx, ctx->k_ipad, 64); |
322 | } | 322 | } |
323 | 323 | ||
324 | /*********************************************************************** | 324 | /*********************************************************************** |
@@ -328,7 +328,7 @@ void | |||
328 | hmac_md5_update(const unsigned char *text, int text_len, | 328 | hmac_md5_update(const unsigned char *text, int text_len, |
329 | struct HMACMD5Context *ctx) | 329 | struct HMACMD5Context *ctx) |
330 | { | 330 | { |
331 | MD5Update(&ctx->ctx, text, text_len); /* then text of datagram */ | 331 | cifs_MD5_update(&ctx->ctx, text, text_len); /* then text of datagram */ |
332 | } | 332 | } |
333 | 333 | ||
334 | /*********************************************************************** | 334 | /*********************************************************************** |
@@ -339,12 +339,12 @@ hmac_md5_final(unsigned char *digest, struct HMACMD5Context *ctx) | |||
339 | { | 339 | { |
340 | struct MD5Context ctx_o; | 340 | struct MD5Context ctx_o; |
341 | 341 | ||
342 | MD5Final(digest, &ctx->ctx); | 342 | cifs_MD5_final(digest, &ctx->ctx); |
343 | 343 | ||
344 | MD5Init(&ctx_o); | 344 | cifs_MD5_init(&ctx_o); |
345 | MD5Update(&ctx_o, ctx->k_opad, 64); | 345 | cifs_MD5_update(&ctx_o, ctx->k_opad, 64); |
346 | MD5Update(&ctx_o, digest, 16); | 346 | cifs_MD5_update(&ctx_o, digest, 16); |
347 | MD5Final(digest, &ctx_o); | 347 | cifs_MD5_final(digest, &ctx_o); |
348 | } | 348 | } |
349 | 349 | ||
350 | /*********************************************************** | 350 | /*********************************************************** |
diff --git a/fs/cifs/md5.h b/fs/cifs/md5.h index f7d4f4197bac..6fba8cb402fd 100644 --- a/fs/cifs/md5.h +++ b/fs/cifs/md5.h | |||
@@ -20,10 +20,10 @@ struct HMACMD5Context { | |||
20 | }; | 20 | }; |
21 | #endif /* _HMAC_MD5_H */ | 21 | #endif /* _HMAC_MD5_H */ |
22 | 22 | ||
23 | void MD5Init(struct MD5Context *context); | 23 | void cifs_MD5_init(struct MD5Context *context); |
24 | void MD5Update(struct MD5Context *context, unsigned char const *buf, | 24 | void cifs_MD5_update(struct MD5Context *context, unsigned char const *buf, |
25 | unsigned len); | 25 | unsigned len); |
26 | void MD5Final(unsigned char digest[16], struct MD5Context *context); | 26 | void cifs_MD5_final(unsigned char digest[16], struct MD5Context *context); |
27 | 27 | ||
28 | /* The following definitions come from lib/hmacmd5.c */ | 28 | /* The following definitions come from lib/hmacmd5.c */ |
29 | 29 | ||
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 7ebe6599ed3a..0ad3e2d116a6 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c | |||
@@ -154,81 +154,8 @@ void DeleteTconOplockQEntries(struct cifsTconInfo *tcon) | |||
154 | spin_unlock(&GlobalMid_Lock); | 154 | spin_unlock(&GlobalMid_Lock); |
155 | } | 155 | } |
156 | 156 | ||
157 | int | ||
158 | smb_send(struct socket *ssocket, struct smb_hdr *smb_buffer, | ||
159 | unsigned int smb_buf_length, struct sockaddr *sin, bool noblocksnd) | ||
160 | { | ||
161 | int rc = 0; | ||
162 | int i = 0; | ||
163 | struct msghdr smb_msg; | ||
164 | struct kvec iov; | ||
165 | unsigned len = smb_buf_length + 4; | ||
166 | |||
167 | if (ssocket == NULL) | ||
168 | return -ENOTSOCK; /* BB eventually add reconnect code here */ | ||
169 | iov.iov_base = smb_buffer; | ||
170 | iov.iov_len = len; | ||
171 | |||
172 | smb_msg.msg_name = sin; | ||
173 | smb_msg.msg_namelen = sizeof(struct sockaddr); | ||
174 | smb_msg.msg_control = NULL; | ||
175 | smb_msg.msg_controllen = 0; | ||
176 | if (noblocksnd) | ||
177 | smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; | ||
178 | else | ||
179 | smb_msg.msg_flags = MSG_NOSIGNAL; | ||
180 | |||
181 | /* smb header is converted in header_assemble. bcc and rest of SMB word | ||
182 | area, and byte area if necessary, is converted to littleendian in | ||
183 | cifssmb.c and RFC1001 len is converted to bigendian in smb_send | ||
184 | Flags2 is converted in SendReceive */ | ||
185 | |||
186 | smb_buffer->smb_buf_length = cpu_to_be32(smb_buffer->smb_buf_length); | ||
187 | cFYI(1, ("Sending smb of length %d", smb_buf_length)); | ||
188 | dump_smb(smb_buffer, len); | ||
189 | |||
190 | while (len > 0) { | ||
191 | rc = kernel_sendmsg(ssocket, &smb_msg, &iov, 1, len); | ||
192 | if ((rc == -ENOSPC) || (rc == -EAGAIN)) { | ||
193 | i++; | ||
194 | /* smaller timeout here than send2 since smaller size */ | ||
195 | /* Although it may not be required, this also is smaller | ||
196 | oplock break time */ | ||
197 | if (i > 12) { | ||
198 | cERROR(1, | ||
199 | ("sends on sock %p stuck for 7 seconds", | ||
200 | ssocket)); | ||
201 | rc = -EAGAIN; | ||
202 | break; | ||
203 | } | ||
204 | msleep(1 << i); | ||
205 | continue; | ||
206 | } | ||
207 | if (rc < 0) | ||
208 | break; | ||
209 | else | ||
210 | i = 0; /* reset i after each successful send */ | ||
211 | iov.iov_base += rc; | ||
212 | iov.iov_len -= rc; | ||
213 | len -= rc; | ||
214 | } | ||
215 | |||
216 | if (rc < 0) { | ||
217 | cERROR(1, ("Error %d sending data on socket to server", rc)); | ||
218 | } else { | ||
219 | rc = 0; | ||
220 | } | ||
221 | |||
222 | /* Don't want to modify the buffer as a | ||
223 | side effect of this call. */ | ||
224 | smb_buffer->smb_buf_length = smb_buf_length; | ||
225 | |||
226 | return rc; | ||
227 | } | ||
228 | |||
229 | static int | 157 | static int |
230 | smb_send2(struct TCP_Server_Info *server, struct kvec *iov, int n_vec, | 158 | smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) |
231 | struct sockaddr *sin, bool noblocksnd) | ||
232 | { | 159 | { |
233 | int rc = 0; | 160 | int rc = 0; |
234 | int i = 0; | 161 | int i = 0; |
@@ -243,11 +170,11 @@ smb_send2(struct TCP_Server_Info *server, struct kvec *iov, int n_vec, | |||
243 | if (ssocket == NULL) | 170 | if (ssocket == NULL) |
244 | return -ENOTSOCK; /* BB eventually add reconnect code here */ | 171 | return -ENOTSOCK; /* BB eventually add reconnect code here */ |
245 | 172 | ||
246 | smb_msg.msg_name = sin; | 173 | smb_msg.msg_name = (struct sockaddr *) &server->addr.sockAddr; |
247 | smb_msg.msg_namelen = sizeof(struct sockaddr); | 174 | smb_msg.msg_namelen = sizeof(struct sockaddr); |
248 | smb_msg.msg_control = NULL; | 175 | smb_msg.msg_control = NULL; |
249 | smb_msg.msg_controllen = 0; | 176 | smb_msg.msg_controllen = 0; |
250 | if (noblocksnd) | 177 | if (server->noblocksnd) |
251 | smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; | 178 | smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; |
252 | else | 179 | else |
253 | smb_msg.msg_flags = MSG_NOSIGNAL; | 180 | smb_msg.msg_flags = MSG_NOSIGNAL; |
@@ -272,7 +199,25 @@ smb_send2(struct TCP_Server_Info *server, struct kvec *iov, int n_vec, | |||
272 | n_vec - first_vec, total_len); | 199 | n_vec - first_vec, total_len); |
273 | if ((rc == -ENOSPC) || (rc == -EAGAIN)) { | 200 | if ((rc == -ENOSPC) || (rc == -EAGAIN)) { |
274 | i++; | 201 | i++; |
275 | if (i >= 14) { | 202 | /* if blocking send we try 3 times, since each can block |
203 | for 5 seconds. For nonblocking we have to try more | ||
204 | but wait increasing amounts of time allowing time for | ||
205 | socket to clear. The overall time we wait in either | ||
206 | case to send on the socket is about 15 seconds. | ||
207 | Similarly we wait for 15 seconds for | ||
208 | a response from the server in SendReceive[2] | ||
209 | for the server to send a response back for | ||
210 | most types of requests (except SMB Write | ||
211 | past end of file which can be slow, and | ||
212 | blocking lock operations). NFS waits slightly longer | ||
213 | than CIFS, but this can make it take longer for | ||
214 | nonresponsive servers to be detected and 15 seconds | ||
215 | is more than enough time for modern networks to | ||
216 | send a packet. In most cases if we fail to send | ||
217 | after the retries we will kill the socket and | ||
218 | reconnect which may clear the network problem. | ||
219 | */ | ||
220 | if ((i >= 14) || (!server->noblocksnd && (i > 2))) { | ||
276 | cERROR(1, | 221 | cERROR(1, |
277 | ("sends on sock %p stuck for 15 seconds", | 222 | ("sends on sock %p stuck for 15 seconds", |
278 | ssocket)); | 223 | ssocket)); |
@@ -339,6 +284,18 @@ smb_send2(struct TCP_Server_Info *server, struct kvec *iov, int n_vec, | |||
339 | return rc; | 284 | return rc; |
340 | } | 285 | } |
341 | 286 | ||
287 | int | ||
288 | smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, | ||
289 | unsigned int smb_buf_length) | ||
290 | { | ||
291 | struct kvec iov; | ||
292 | |||
293 | iov.iov_base = smb_buffer; | ||
294 | iov.iov_len = smb_buf_length + 4; | ||
295 | |||
296 | return smb_sendv(server, &iov, 1); | ||
297 | } | ||
298 | |||
342 | static int wait_for_free_request(struct cifsSesInfo *ses, const int long_op) | 299 | static int wait_for_free_request(struct cifsSesInfo *ses, const int long_op) |
343 | { | 300 | { |
344 | if (long_op == CIFS_ASYNC_OP) { | 301 | if (long_op == CIFS_ASYNC_OP) { |
@@ -540,9 +497,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
540 | #ifdef CONFIG_CIFS_STATS2 | 497 | #ifdef CONFIG_CIFS_STATS2 |
541 | atomic_inc(&ses->server->inSend); | 498 | atomic_inc(&ses->server->inSend); |
542 | #endif | 499 | #endif |
543 | rc = smb_send2(ses->server, iov, n_vec, | 500 | rc = smb_sendv(ses->server, iov, n_vec); |
544 | (struct sockaddr *) &(ses->server->addr.sockAddr), | ||
545 | ses->server->noblocksnd); | ||
546 | #ifdef CONFIG_CIFS_STATS2 | 501 | #ifdef CONFIG_CIFS_STATS2 |
547 | atomic_dec(&ses->server->inSend); | 502 | atomic_dec(&ses->server->inSend); |
548 | midQ->when_sent = jiffies; | 503 | midQ->when_sent = jiffies; |
@@ -736,9 +691,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
736 | #ifdef CONFIG_CIFS_STATS2 | 691 | #ifdef CONFIG_CIFS_STATS2 |
737 | atomic_inc(&ses->server->inSend); | 692 | atomic_inc(&ses->server->inSend); |
738 | #endif | 693 | #endif |
739 | rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length, | 694 | rc = smb_send(ses->server, in_buf, in_buf->smb_buf_length); |
740 | (struct sockaddr *) &(ses->server->addr.sockAddr), | ||
741 | ses->server->noblocksnd); | ||
742 | #ifdef CONFIG_CIFS_STATS2 | 695 | #ifdef CONFIG_CIFS_STATS2 |
743 | atomic_dec(&ses->server->inSend); | 696 | atomic_dec(&ses->server->inSend); |
744 | midQ->when_sent = jiffies; | 697 | midQ->when_sent = jiffies; |
@@ -879,9 +832,7 @@ send_nt_cancel(struct cifsTconInfo *tcon, struct smb_hdr *in_buf, | |||
879 | mutex_unlock(&ses->server->srv_mutex); | 832 | mutex_unlock(&ses->server->srv_mutex); |
880 | return rc; | 833 | return rc; |
881 | } | 834 | } |
882 | rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length, | 835 | rc = smb_send(ses->server, in_buf, in_buf->smb_buf_length); |
883 | (struct sockaddr *) &(ses->server->addr.sockAddr), | ||
884 | ses->server->noblocksnd); | ||
885 | mutex_unlock(&ses->server->srv_mutex); | 836 | mutex_unlock(&ses->server->srv_mutex); |
886 | return rc; | 837 | return rc; |
887 | } | 838 | } |
@@ -973,9 +924,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
973 | #ifdef CONFIG_CIFS_STATS2 | 924 | #ifdef CONFIG_CIFS_STATS2 |
974 | atomic_inc(&ses->server->inSend); | 925 | atomic_inc(&ses->server->inSend); |
975 | #endif | 926 | #endif |
976 | rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length, | 927 | rc = smb_send(ses->server, in_buf, in_buf->smb_buf_length); |
977 | (struct sockaddr *) &(ses->server->addr.sockAddr), | ||
978 | ses->server->noblocksnd); | ||
979 | #ifdef CONFIG_CIFS_STATS2 | 928 | #ifdef CONFIG_CIFS_STATS2 |
980 | atomic_dec(&ses->server->inSend); | 929 | atomic_dec(&ses->server->inSend); |
981 | midQ->when_sent = jiffies; | 930 | midQ->when_sent = jiffies; |
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c index 5235c67e7594..9c6d815dd191 100644 --- a/fs/compat_ioctl.c +++ b/fs/compat_ioctl.c | |||
@@ -538,6 +538,7 @@ static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg) | |||
538 | * cannot be fixed without breaking all existing apps. | 538 | * cannot be fixed without breaking all existing apps. |
539 | */ | 539 | */ |
540 | case TUNSETIFF: | 540 | case TUNSETIFF: |
541 | case TUNGETIFF: | ||
541 | case SIOCGIFFLAGS: | 542 | case SIOCGIFFLAGS: |
542 | case SIOCGIFMETRIC: | 543 | case SIOCGIFMETRIC: |
543 | case SIOCGIFMTU: | 544 | case SIOCGIFMTU: |
@@ -784,7 +785,7 @@ static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) | |||
784 | 785 | ||
785 | if (copy_in_user(&sgio->status, &sgio32->status, | 786 | if (copy_in_user(&sgio->status, &sgio32->status, |
786 | (4 * sizeof(unsigned char)) + | 787 | (4 * sizeof(unsigned char)) + |
787 | (2 * sizeof(unsigned (short))) + | 788 | (2 * sizeof(unsigned short)) + |
788 | (3 * sizeof(int)))) | 789 | (3 * sizeof(int)))) |
789 | return -EFAULT; | 790 | return -EFAULT; |
790 | 791 | ||
@@ -1982,6 +1983,11 @@ COMPATIBLE_IOCTL(TUNSETNOCSUM) | |||
1982 | COMPATIBLE_IOCTL(TUNSETDEBUG) | 1983 | COMPATIBLE_IOCTL(TUNSETDEBUG) |
1983 | COMPATIBLE_IOCTL(TUNSETPERSIST) | 1984 | COMPATIBLE_IOCTL(TUNSETPERSIST) |
1984 | COMPATIBLE_IOCTL(TUNSETOWNER) | 1985 | COMPATIBLE_IOCTL(TUNSETOWNER) |
1986 | COMPATIBLE_IOCTL(TUNSETLINK) | ||
1987 | COMPATIBLE_IOCTL(TUNSETGROUP) | ||
1988 | COMPATIBLE_IOCTL(TUNGETFEATURES) | ||
1989 | COMPATIBLE_IOCTL(TUNSETOFFLOAD) | ||
1990 | COMPATIBLE_IOCTL(TUNSETTXFILTER) | ||
1985 | /* Big V */ | 1991 | /* Big V */ |
1986 | COMPATIBLE_IOCTL(VT_SETMODE) | 1992 | COMPATIBLE_IOCTL(VT_SETMODE) |
1987 | COMPATIBLE_IOCTL(VT_GETMODE) | 1993 | COMPATIBLE_IOCTL(VT_GETMODE) |
@@ -2573,6 +2579,7 @@ HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc) | |||
2573 | HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc) | 2579 | HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc) |
2574 | HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc) | 2580 | HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc) |
2575 | HANDLE_IOCTL(TUNSETIFF, dev_ifsioc) | 2581 | HANDLE_IOCTL(TUNSETIFF, dev_ifsioc) |
2582 | HANDLE_IOCTL(TUNGETIFF, dev_ifsioc) | ||
2576 | HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl) | 2583 | HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl) |
2577 | HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl) | 2584 | HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl) |
2578 | HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl) | 2585 | HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl) |
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index c01e043670e2..f6caeb1d1106 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -1716,7 +1716,7 @@ static int ecryptfs_copy_filename(char **copied_name, size_t *copied_name_size, | |||
1716 | { | 1716 | { |
1717 | int rc = 0; | 1717 | int rc = 0; |
1718 | 1718 | ||
1719 | (*copied_name) = kmalloc((name_size + 2), GFP_KERNEL); | 1719 | (*copied_name) = kmalloc((name_size + 1), GFP_KERNEL); |
1720 | if (!(*copied_name)) { | 1720 | if (!(*copied_name)) { |
1721 | rc = -ENOMEM; | 1721 | rc = -ENOMEM; |
1722 | goto out; | 1722 | goto out; |
@@ -1726,7 +1726,7 @@ static int ecryptfs_copy_filename(char **copied_name, size_t *copied_name_size, | |||
1726 | * in printing out the | 1726 | * in printing out the |
1727 | * string in debug | 1727 | * string in debug |
1728 | * messages */ | 1728 | * messages */ |
1729 | (*copied_name_size) = (name_size + 1); | 1729 | (*copied_name_size) = name_size; |
1730 | out: | 1730 | out: |
1731 | return rc; | 1731 | return rc; |
1732 | } | 1732 | } |
diff --git a/fs/eventpoll.c b/fs/eventpoll.c index ba2f9ec71192..011b9b8c90c6 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c | |||
@@ -234,8 +234,6 @@ struct ep_pqueue { | |||
234 | /* | 234 | /* |
235 | * Configuration options available inside /proc/sys/fs/epoll/ | 235 | * Configuration options available inside /proc/sys/fs/epoll/ |
236 | */ | 236 | */ |
237 | /* Maximum number of epoll devices, per user */ | ||
238 | static int max_user_instances __read_mostly; | ||
239 | /* Maximum number of epoll watched descriptors, per user */ | 237 | /* Maximum number of epoll watched descriptors, per user */ |
240 | static int max_user_watches __read_mostly; | 238 | static int max_user_watches __read_mostly; |
241 | 239 | ||
@@ -261,14 +259,6 @@ static int zero; | |||
261 | 259 | ||
262 | ctl_table epoll_table[] = { | 260 | ctl_table epoll_table[] = { |
263 | { | 261 | { |
264 | .procname = "max_user_instances", | ||
265 | .data = &max_user_instances, | ||
266 | .maxlen = sizeof(int), | ||
267 | .mode = 0644, | ||
268 | .proc_handler = &proc_dointvec_minmax, | ||
269 | .extra1 = &zero, | ||
270 | }, | ||
271 | { | ||
272 | .procname = "max_user_watches", | 262 | .procname = "max_user_watches", |
273 | .data = &max_user_watches, | 263 | .data = &max_user_watches, |
274 | .maxlen = sizeof(int), | 264 | .maxlen = sizeof(int), |
@@ -491,7 +481,6 @@ static void ep_free(struct eventpoll *ep) | |||
491 | 481 | ||
492 | mutex_unlock(&epmutex); | 482 | mutex_unlock(&epmutex); |
493 | mutex_destroy(&ep->mtx); | 483 | mutex_destroy(&ep->mtx); |
494 | atomic_dec(&ep->user->epoll_devs); | ||
495 | free_uid(ep->user); | 484 | free_uid(ep->user); |
496 | kfree(ep); | 485 | kfree(ep); |
497 | } | 486 | } |
@@ -581,10 +570,6 @@ static int ep_alloc(struct eventpoll **pep) | |||
581 | struct eventpoll *ep; | 570 | struct eventpoll *ep; |
582 | 571 | ||
583 | user = get_current_user(); | 572 | user = get_current_user(); |
584 | error = -EMFILE; | ||
585 | if (unlikely(atomic_read(&user->epoll_devs) >= | ||
586 | max_user_instances)) | ||
587 | goto free_uid; | ||
588 | error = -ENOMEM; | 573 | error = -ENOMEM; |
589 | ep = kzalloc(sizeof(*ep), GFP_KERNEL); | 574 | ep = kzalloc(sizeof(*ep), GFP_KERNEL); |
590 | if (unlikely(!ep)) | 575 | if (unlikely(!ep)) |
@@ -1141,7 +1126,6 @@ SYSCALL_DEFINE1(epoll_create1, int, flags) | |||
1141 | flags & O_CLOEXEC); | 1126 | flags & O_CLOEXEC); |
1142 | if (fd < 0) | 1127 | if (fd < 0) |
1143 | ep_free(ep); | 1128 | ep_free(ep); |
1144 | atomic_inc(&ep->user->epoll_devs); | ||
1145 | 1129 | ||
1146 | error_return: | 1130 | error_return: |
1147 | DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n", | 1131 | DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n", |
@@ -1366,8 +1350,10 @@ static int __init eventpoll_init(void) | |||
1366 | struct sysinfo si; | 1350 | struct sysinfo si; |
1367 | 1351 | ||
1368 | si_meminfo(&si); | 1352 | si_meminfo(&si); |
1369 | max_user_instances = 128; | 1353 | /* |
1370 | max_user_watches = (((si.totalram - si.totalhigh) / 32) << PAGE_SHIFT) / | 1354 | * Allows top 4% of lomem to be allocated for epoll watches (per user). |
1355 | */ | ||
1356 | max_user_watches = (((si.totalram - si.totalhigh) / 25) << PAGE_SHIFT) / | ||
1371 | EP_ITEM_COST; | 1357 | EP_ITEM_COST; |
1372 | 1358 | ||
1373 | /* Initialize the structure used to perform safe poll wait head wake ups */ | 1359 | /* Initialize the structure used to perform safe poll wait head wake ups */ |
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c index 69a3d19ca9fd..4db4ffa1edad 100644 --- a/fs/ext3/namei.c +++ b/fs/ext3/namei.c | |||
@@ -1358,7 +1358,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry, | |||
1358 | struct fake_dirent *fde; | 1358 | struct fake_dirent *fde; |
1359 | 1359 | ||
1360 | blocksize = dir->i_sb->s_blocksize; | 1360 | blocksize = dir->i_sb->s_blocksize; |
1361 | dxtrace(printk("Creating index\n")); | 1361 | dxtrace(printk(KERN_DEBUG "Creating index: inode %lu\n", dir->i_ino)); |
1362 | retval = ext3_journal_get_write_access(handle, bh); | 1362 | retval = ext3_journal_get_write_access(handle, bh); |
1363 | if (retval) { | 1363 | if (retval) { |
1364 | ext3_std_error(dir->i_sb, retval); | 1364 | ext3_std_error(dir->i_sb, retval); |
@@ -1367,6 +1367,19 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry, | |||
1367 | } | 1367 | } |
1368 | root = (struct dx_root *) bh->b_data; | 1368 | root = (struct dx_root *) bh->b_data; |
1369 | 1369 | ||
1370 | /* The 0th block becomes the root, move the dirents out */ | ||
1371 | fde = &root->dotdot; | ||
1372 | de = (struct ext3_dir_entry_2 *)((char *)fde + | ||
1373 | ext3_rec_len_from_disk(fde->rec_len)); | ||
1374 | if ((char *) de >= (((char *) root) + blocksize)) { | ||
1375 | ext3_error(dir->i_sb, __func__, | ||
1376 | "invalid rec_len for '..' in inode %lu", | ||
1377 | dir->i_ino); | ||
1378 | brelse(bh); | ||
1379 | return -EIO; | ||
1380 | } | ||
1381 | len = ((char *) root) + blocksize - (char *) de; | ||
1382 | |||
1370 | bh2 = ext3_append (handle, dir, &block, &retval); | 1383 | bh2 = ext3_append (handle, dir, &block, &retval); |
1371 | if (!(bh2)) { | 1384 | if (!(bh2)) { |
1372 | brelse(bh); | 1385 | brelse(bh); |
@@ -1375,11 +1388,6 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry, | |||
1375 | EXT3_I(dir)->i_flags |= EXT3_INDEX_FL; | 1388 | EXT3_I(dir)->i_flags |= EXT3_INDEX_FL; |
1376 | data1 = bh2->b_data; | 1389 | data1 = bh2->b_data; |
1377 | 1390 | ||
1378 | /* The 0th block becomes the root, move the dirents out */ | ||
1379 | fde = &root->dotdot; | ||
1380 | de = (struct ext3_dir_entry_2 *)((char *)fde + | ||
1381 | ext3_rec_len_from_disk(fde->rec_len)); | ||
1382 | len = ((char *) root) + blocksize - (char *) de; | ||
1383 | memcpy (data1, de, len); | 1391 | memcpy (data1, de, len); |
1384 | de = (struct ext3_dir_entry_2 *) data1; | 1392 | de = (struct ext3_dir_entry_2 *) data1; |
1385 | top = data1 + len; | 1393 | top = data1 + len; |
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index 6bba06b09dd1..9a50b8052dcf 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c | |||
@@ -684,15 +684,15 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb) | |||
684 | gdp = ext4_get_group_desc(sb, i, NULL); | 684 | gdp = ext4_get_group_desc(sb, i, NULL); |
685 | if (!gdp) | 685 | if (!gdp) |
686 | continue; | 686 | continue; |
687 | desc_count += le16_to_cpu(gdp->bg_free_blocks_count); | 687 | desc_count += ext4_free_blks_count(sb, gdp); |
688 | brelse(bitmap_bh); | 688 | brelse(bitmap_bh); |
689 | bitmap_bh = ext4_read_block_bitmap(sb, i); | 689 | bitmap_bh = ext4_read_block_bitmap(sb, i); |
690 | if (bitmap_bh == NULL) | 690 | if (bitmap_bh == NULL) |
691 | continue; | 691 | continue; |
692 | 692 | ||
693 | x = ext4_count_free(bitmap_bh, sb->s_blocksize); | 693 | x = ext4_count_free(bitmap_bh, sb->s_blocksize); |
694 | printk(KERN_DEBUG "group %lu: stored = %d, counted = %u\n", | 694 | printk(KERN_DEBUG "group %u: stored = %d, counted = %u\n", |
695 | i, le16_to_cpu(gdp->bg_free_blocks_count), x); | 695 | i, ext4_free_blks_count(sb, gdp), x); |
696 | bitmap_count += x; | 696 | bitmap_count += x; |
697 | } | 697 | } |
698 | brelse(bitmap_bh); | 698 | brelse(bitmap_bh); |
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index c668e4377d76..aafc9eba1c25 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -1206,8 +1206,11 @@ static inline void ext4_r_blocks_count_set(struct ext4_super_block *es, | |||
1206 | 1206 | ||
1207 | static inline loff_t ext4_isize(struct ext4_inode *raw_inode) | 1207 | static inline loff_t ext4_isize(struct ext4_inode *raw_inode) |
1208 | { | 1208 | { |
1209 | return ((loff_t)le32_to_cpu(raw_inode->i_size_high) << 32) | | 1209 | if (S_ISREG(le16_to_cpu(raw_inode->i_mode))) |
1210 | le32_to_cpu(raw_inode->i_size_lo); | 1210 | return ((loff_t)le32_to_cpu(raw_inode->i_size_high) << 32) | |
1211 | le32_to_cpu(raw_inode->i_size_lo); | ||
1212 | else | ||
1213 | return (loff_t) le32_to_cpu(raw_inode->i_size_lo); | ||
1211 | } | 1214 | } |
1212 | 1215 | ||
1213 | static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size) | 1216 | static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size) |
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 54bf0623a9ae..e2eab196875f 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -3048,7 +3048,7 @@ retry: | |||
3048 | WARN_ON(ret <= 0); | 3048 | WARN_ON(ret <= 0); |
3049 | printk(KERN_ERR "%s: ext4_ext_get_blocks " | 3049 | printk(KERN_ERR "%s: ext4_ext_get_blocks " |
3050 | "returned error inode#%lu, block=%u, " | 3050 | "returned error inode#%lu, block=%u, " |
3051 | "max_blocks=%lu", __func__, | 3051 | "max_blocks=%u", __func__, |
3052 | inode->i_ino, block, max_blocks); | 3052 | inode->i_ino, block, max_blocks); |
3053 | #endif | 3053 | #endif |
3054 | ext4_mark_inode_dirty(handle, inode); | 3054 | ext4_mark_inode_dirty(handle, inode); |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index a6444cee0c7e..03ba20be1329 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -360,9 +360,9 @@ static int ext4_block_to_path(struct inode *inode, | |||
360 | final = ptrs; | 360 | final = ptrs; |
361 | } else { | 361 | } else { |
362 | ext4_warning(inode->i_sb, "ext4_block_to_path", | 362 | ext4_warning(inode->i_sb, "ext4_block_to_path", |
363 | "block %lu > max", | 363 | "block %lu > max in inode %lu", |
364 | i_block + direct_blocks + | 364 | i_block + direct_blocks + |
365 | indirect_blocks + double_blocks); | 365 | indirect_blocks + double_blocks, inode->i_ino); |
366 | } | 366 | } |
367 | if (boundary) | 367 | if (boundary) |
368 | *boundary = final - 1 - (i_block & (ptrs - 1)); | 368 | *boundary = final - 1 - (i_block & (ptrs - 1)); |
@@ -2821,9 +2821,6 @@ static sector_t ext4_bmap(struct address_space *mapping, sector_t block) | |||
2821 | filemap_write_and_wait(mapping); | 2821 | filemap_write_and_wait(mapping); |
2822 | } | 2822 | } |
2823 | 2823 | ||
2824 | BUG_ON(!EXT4_JOURNAL(inode) && | ||
2825 | EXT4_I(inode)->i_state & EXT4_STATE_JDATA); | ||
2826 | |||
2827 | if (EXT4_JOURNAL(inode) && EXT4_I(inode)->i_state & EXT4_STATE_JDATA) { | 2824 | if (EXT4_JOURNAL(inode) && EXT4_I(inode)->i_state & EXT4_STATE_JDATA) { |
2828 | /* | 2825 | /* |
2829 | * This is a REALLY heavyweight approach, but the use of | 2826 | * This is a REALLY heavyweight approach, but the use of |
@@ -3622,7 +3619,7 @@ static void ext4_free_data(handle_t *handle, struct inode *inode, | |||
3622 | * block pointed to itself, it would have been detached when | 3619 | * block pointed to itself, it would have been detached when |
3623 | * the block was cleared. Check for this instead of OOPSing. | 3620 | * the block was cleared. Check for this instead of OOPSing. |
3624 | */ | 3621 | */ |
3625 | if (bh2jh(this_bh)) | 3622 | if ((EXT4_JOURNAL(inode) == NULL) || bh2jh(this_bh)) |
3626 | ext4_handle_dirty_metadata(handle, inode, this_bh); | 3623 | ext4_handle_dirty_metadata(handle, inode, this_bh); |
3627 | else | 3624 | else |
3628 | ext4_error(inode->i_sb, __func__, | 3625 | ext4_error(inode->i_sb, __func__, |
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 918aec0c8a11..deba54f6cbed 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
@@ -3025,7 +3025,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, | |||
3025 | goto out_err; | 3025 | goto out_err; |
3026 | 3026 | ||
3027 | ext4_debug("using block group %u(%d)\n", ac->ac_b_ex.fe_group, | 3027 | ext4_debug("using block group %u(%d)\n", ac->ac_b_ex.fe_group, |
3028 | gdp->bg_free_blocks_count); | 3028 | ext4_free_blks_count(sb, gdp)); |
3029 | 3029 | ||
3030 | err = ext4_journal_get_write_access(handle, gdp_bh); | 3030 | err = ext4_journal_get_write_access(handle, gdp_bh); |
3031 | if (err) | 3031 | if (err) |
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index fec0b4c2f5f1..ba702bd7910d 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
@@ -1368,7 +1368,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry, | |||
1368 | struct fake_dirent *fde; | 1368 | struct fake_dirent *fde; |
1369 | 1369 | ||
1370 | blocksize = dir->i_sb->s_blocksize; | 1370 | blocksize = dir->i_sb->s_blocksize; |
1371 | dxtrace(printk(KERN_DEBUG "Creating index\n")); | 1371 | dxtrace(printk(KERN_DEBUG "Creating index: inode %lu\n", dir->i_ino)); |
1372 | retval = ext4_journal_get_write_access(handle, bh); | 1372 | retval = ext4_journal_get_write_access(handle, bh); |
1373 | if (retval) { | 1373 | if (retval) { |
1374 | ext4_std_error(dir->i_sb, retval); | 1374 | ext4_std_error(dir->i_sb, retval); |
@@ -1377,6 +1377,20 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry, | |||
1377 | } | 1377 | } |
1378 | root = (struct dx_root *) bh->b_data; | 1378 | root = (struct dx_root *) bh->b_data; |
1379 | 1379 | ||
1380 | /* The 0th block becomes the root, move the dirents out */ | ||
1381 | fde = &root->dotdot; | ||
1382 | de = (struct ext4_dir_entry_2 *)((char *)fde + | ||
1383 | ext4_rec_len_from_disk(fde->rec_len)); | ||
1384 | if ((char *) de >= (((char *) root) + blocksize)) { | ||
1385 | ext4_error(dir->i_sb, __func__, | ||
1386 | "invalid rec_len for '..' in inode %lu", | ||
1387 | dir->i_ino); | ||
1388 | brelse(bh); | ||
1389 | return -EIO; | ||
1390 | } | ||
1391 | len = ((char *) root) + blocksize - (char *) de; | ||
1392 | |||
1393 | /* Allocate new block for the 0th block's dirents */ | ||
1380 | bh2 = ext4_append(handle, dir, &block, &retval); | 1394 | bh2 = ext4_append(handle, dir, &block, &retval); |
1381 | if (!(bh2)) { | 1395 | if (!(bh2)) { |
1382 | brelse(bh); | 1396 | brelse(bh); |
@@ -1385,11 +1399,6 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry, | |||
1385 | EXT4_I(dir)->i_flags |= EXT4_INDEX_FL; | 1399 | EXT4_I(dir)->i_flags |= EXT4_INDEX_FL; |
1386 | data1 = bh2->b_data; | 1400 | data1 = bh2->b_data; |
1387 | 1401 | ||
1388 | /* The 0th block becomes the root, move the dirents out */ | ||
1389 | fde = &root->dotdot; | ||
1390 | de = (struct ext4_dir_entry_2 *)((char *)fde + | ||
1391 | ext4_rec_len_from_disk(fde->rec_len)); | ||
1392 | len = ((char *) root) + blocksize - (char *) de; | ||
1393 | memcpy (data1, de, len); | 1402 | memcpy (data1, de, len); |
1394 | de = (struct ext4_dir_entry_2 *) data1; | 1403 | de = (struct ext4_dir_entry_2 *) data1; |
1395 | top = data1 + len; | 1404 | top = data1 + len; |
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index c328be5d6885..c06886abd658 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c | |||
@@ -861,12 +861,13 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input) | |||
861 | gdp = (struct ext4_group_desc *)((char *)primary->b_data + | 861 | gdp = (struct ext4_group_desc *)((char *)primary->b_data + |
862 | gdb_off * EXT4_DESC_SIZE(sb)); | 862 | gdb_off * EXT4_DESC_SIZE(sb)); |
863 | 863 | ||
864 | memset(gdp, 0, EXT4_DESC_SIZE(sb)); | ||
864 | ext4_block_bitmap_set(sb, gdp, input->block_bitmap); /* LV FIXME */ | 865 | ext4_block_bitmap_set(sb, gdp, input->block_bitmap); /* LV FIXME */ |
865 | ext4_inode_bitmap_set(sb, gdp, input->inode_bitmap); /* LV FIXME */ | 866 | ext4_inode_bitmap_set(sb, gdp, input->inode_bitmap); /* LV FIXME */ |
866 | ext4_inode_table_set(sb, gdp, input->inode_table); /* LV FIXME */ | 867 | ext4_inode_table_set(sb, gdp, input->inode_table); /* LV FIXME */ |
867 | ext4_free_blks_set(sb, gdp, input->free_blocks_count); | 868 | ext4_free_blks_set(sb, gdp, input->free_blocks_count); |
868 | ext4_free_inodes_set(sb, gdp, EXT4_INODES_PER_GROUP(sb)); | 869 | ext4_free_inodes_set(sb, gdp, EXT4_INODES_PER_GROUP(sb)); |
869 | gdp->bg_flags |= cpu_to_le16(EXT4_BG_INODE_ZEROED); | 870 | gdp->bg_flags = cpu_to_le16(EXT4_BG_INODE_ZEROED); |
870 | gdp->bg_checksum = ext4_group_desc_csum(sbi, input->group, gdp); | 871 | gdp->bg_checksum = ext4_group_desc_csum(sbi, input->group, gdp); |
871 | 872 | ||
872 | /* | 873 | /* |
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 56675306ed81..eb343008eded 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c | |||
@@ -37,10 +37,10 @@ | |||
37 | #include <linux/proc_fs.h> | 37 | #include <linux/proc_fs.h> |
38 | #include <linux/debugfs.h> | 38 | #include <linux/debugfs.h> |
39 | #include <linux/seq_file.h> | 39 | #include <linux/seq_file.h> |
40 | #include <linux/math64.h> | ||
40 | 41 | ||
41 | #include <asm/uaccess.h> | 42 | #include <asm/uaccess.h> |
42 | #include <asm/page.h> | 43 | #include <asm/page.h> |
43 | #include <asm/div64.h> | ||
44 | 44 | ||
45 | EXPORT_SYMBOL(jbd2_journal_start); | 45 | EXPORT_SYMBOL(jbd2_journal_start); |
46 | EXPORT_SYMBOL(jbd2_journal_restart); | 46 | EXPORT_SYMBOL(jbd2_journal_restart); |
@@ -846,8 +846,8 @@ static int jbd2_seq_info_show(struct seq_file *seq, void *v) | |||
846 | jiffies_to_msecs(s->stats->u.run.rs_flushing / s->stats->ts_tid)); | 846 | jiffies_to_msecs(s->stats->u.run.rs_flushing / s->stats->ts_tid)); |
847 | seq_printf(seq, " %ums logging transaction\n", | 847 | seq_printf(seq, " %ums logging transaction\n", |
848 | jiffies_to_msecs(s->stats->u.run.rs_logging / s->stats->ts_tid)); | 848 | jiffies_to_msecs(s->stats->u.run.rs_logging / s->stats->ts_tid)); |
849 | seq_printf(seq, " %luus average transaction commit time\n", | 849 | seq_printf(seq, " %lluus average transaction commit time\n", |
850 | do_div(s->journal->j_average_commit_time, 1000)); | 850 | div_u64(s->journal->j_average_commit_time, 1000)); |
851 | seq_printf(seq, " %lu handles per transaction\n", | 851 | seq_printf(seq, " %lu handles per transaction\n", |
852 | s->stats->u.run.rs_handle_count / s->stats->ts_tid); | 852 | s->stats->u.run.rs_handle_count / s->stats->ts_tid); |
853 | seq_printf(seq, " %lu blocks per transaction\n", | 853 | seq_printf(seq, " %lu blocks per transaction\n", |
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index d861096c9d81..60fe74035db5 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c | |||
@@ -5390,6 +5390,9 @@ int ocfs2_remove_btree_range(struct inode *inode, | |||
5390 | goto out; | 5390 | goto out; |
5391 | } | 5391 | } |
5392 | 5392 | ||
5393 | vfs_dq_free_space_nodirty(inode, | ||
5394 | ocfs2_clusters_to_bytes(inode->i_sb, len)); | ||
5395 | |||
5393 | ret = ocfs2_remove_extent(inode, et, cpos, len, handle, meta_ac, | 5396 | ret = ocfs2_remove_extent(inode, et, cpos, len, handle, meta_ac, |
5394 | dealloc); | 5397 | dealloc); |
5395 | if (ret) { | 5398 | if (ret) { |
diff --git a/fs/ocfs2/dcache.c b/fs/ocfs2/dcache.c index b1cc7c381e88..e9d7c2038c0f 100644 --- a/fs/ocfs2/dcache.c +++ b/fs/ocfs2/dcache.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include "dlmglue.h" | 38 | #include "dlmglue.h" |
39 | #include "file.h" | 39 | #include "file.h" |
40 | #include "inode.h" | 40 | #include "inode.h" |
41 | #include "super.h" | ||
41 | 42 | ||
42 | 43 | ||
43 | static int ocfs2_dentry_revalidate(struct dentry *dentry, | 44 | static int ocfs2_dentry_revalidate(struct dentry *dentry, |
@@ -294,6 +295,34 @@ out_attach: | |||
294 | return ret; | 295 | return ret; |
295 | } | 296 | } |
296 | 297 | ||
298 | static DEFINE_SPINLOCK(dentry_list_lock); | ||
299 | |||
300 | /* We limit the number of dentry locks to drop in one go. We have | ||
301 | * this limit so that we don't starve other users of ocfs2_wq. */ | ||
302 | #define DL_INODE_DROP_COUNT 64 | ||
303 | |||
304 | /* Drop inode references from dentry locks */ | ||
305 | void ocfs2_drop_dl_inodes(struct work_struct *work) | ||
306 | { | ||
307 | struct ocfs2_super *osb = container_of(work, struct ocfs2_super, | ||
308 | dentry_lock_work); | ||
309 | struct ocfs2_dentry_lock *dl; | ||
310 | int drop_count = DL_INODE_DROP_COUNT; | ||
311 | |||
312 | spin_lock(&dentry_list_lock); | ||
313 | while (osb->dentry_lock_list && drop_count--) { | ||
314 | dl = osb->dentry_lock_list; | ||
315 | osb->dentry_lock_list = dl->dl_next; | ||
316 | spin_unlock(&dentry_list_lock); | ||
317 | iput(dl->dl_inode); | ||
318 | kfree(dl); | ||
319 | spin_lock(&dentry_list_lock); | ||
320 | } | ||
321 | if (osb->dentry_lock_list) | ||
322 | queue_work(ocfs2_wq, &osb->dentry_lock_work); | ||
323 | spin_unlock(&dentry_list_lock); | ||
324 | } | ||
325 | |||
297 | /* | 326 | /* |
298 | * ocfs2_dentry_iput() and friends. | 327 | * ocfs2_dentry_iput() and friends. |
299 | * | 328 | * |
@@ -318,16 +347,23 @@ out_attach: | |||
318 | static void ocfs2_drop_dentry_lock(struct ocfs2_super *osb, | 347 | static void ocfs2_drop_dentry_lock(struct ocfs2_super *osb, |
319 | struct ocfs2_dentry_lock *dl) | 348 | struct ocfs2_dentry_lock *dl) |
320 | { | 349 | { |
321 | iput(dl->dl_inode); | ||
322 | ocfs2_simple_drop_lockres(osb, &dl->dl_lockres); | 350 | ocfs2_simple_drop_lockres(osb, &dl->dl_lockres); |
323 | ocfs2_lock_res_free(&dl->dl_lockres); | 351 | ocfs2_lock_res_free(&dl->dl_lockres); |
324 | kfree(dl); | 352 | |
353 | /* We leave dropping of inode reference to ocfs2_wq as that can | ||
354 | * possibly lead to inode deletion which gets tricky */ | ||
355 | spin_lock(&dentry_list_lock); | ||
356 | if (!osb->dentry_lock_list) | ||
357 | queue_work(ocfs2_wq, &osb->dentry_lock_work); | ||
358 | dl->dl_next = osb->dentry_lock_list; | ||
359 | osb->dentry_lock_list = dl; | ||
360 | spin_unlock(&dentry_list_lock); | ||
325 | } | 361 | } |
326 | 362 | ||
327 | void ocfs2_dentry_lock_put(struct ocfs2_super *osb, | 363 | void ocfs2_dentry_lock_put(struct ocfs2_super *osb, |
328 | struct ocfs2_dentry_lock *dl) | 364 | struct ocfs2_dentry_lock *dl) |
329 | { | 365 | { |
330 | int unlock = 0; | 366 | int unlock; |
331 | 367 | ||
332 | BUG_ON(dl->dl_count == 0); | 368 | BUG_ON(dl->dl_count == 0); |
333 | 369 | ||
diff --git a/fs/ocfs2/dcache.h b/fs/ocfs2/dcache.h index c091c34d9883..d06e16c06640 100644 --- a/fs/ocfs2/dcache.h +++ b/fs/ocfs2/dcache.h | |||
@@ -29,8 +29,13 @@ | |||
29 | extern struct dentry_operations ocfs2_dentry_ops; | 29 | extern struct dentry_operations ocfs2_dentry_ops; |
30 | 30 | ||
31 | struct ocfs2_dentry_lock { | 31 | struct ocfs2_dentry_lock { |
32 | /* Use count of dentry lock */ | ||
32 | unsigned int dl_count; | 33 | unsigned int dl_count; |
33 | u64 dl_parent_blkno; | 34 | union { |
35 | /* Linked list of dentry locks to release */ | ||
36 | struct ocfs2_dentry_lock *dl_next; | ||
37 | u64 dl_parent_blkno; | ||
38 | }; | ||
34 | 39 | ||
35 | /* | 40 | /* |
36 | * The ocfs2_dentry_lock keeps an inode reference until | 41 | * The ocfs2_dentry_lock keeps an inode reference until |
@@ -47,6 +52,8 @@ int ocfs2_dentry_attach_lock(struct dentry *dentry, struct inode *inode, | |||
47 | void ocfs2_dentry_lock_put(struct ocfs2_super *osb, | 52 | void ocfs2_dentry_lock_put(struct ocfs2_super *osb, |
48 | struct ocfs2_dentry_lock *dl); | 53 | struct ocfs2_dentry_lock *dl); |
49 | 54 | ||
55 | void ocfs2_drop_dl_inodes(struct work_struct *work); | ||
56 | |||
50 | struct dentry *ocfs2_find_local_alias(struct inode *inode, u64 parent_blkno, | 57 | struct dentry *ocfs2_find_local_alias(struct inode *inode, u64 parent_blkno, |
51 | int skip_unhashed); | 58 | int skip_unhashed); |
52 | 59 | ||
diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c index b0c4cadd4c45..206a2370876a 100644 --- a/fs/ocfs2/dlmglue.c +++ b/fs/ocfs2/dlmglue.c | |||
@@ -2860,6 +2860,10 @@ static void ocfs2_unlock_ast(void *opaque, int error) | |||
2860 | case OCFS2_UNLOCK_CANCEL_CONVERT: | 2860 | case OCFS2_UNLOCK_CANCEL_CONVERT: |
2861 | mlog(0, "Cancel convert success for %s\n", lockres->l_name); | 2861 | mlog(0, "Cancel convert success for %s\n", lockres->l_name); |
2862 | lockres->l_action = OCFS2_AST_INVALID; | 2862 | lockres->l_action = OCFS2_AST_INVALID; |
2863 | /* Downconvert thread may have requeued this lock, we | ||
2864 | * need to wake it. */ | ||
2865 | if (lockres->l_flags & OCFS2_LOCK_BLOCKED) | ||
2866 | ocfs2_wake_downconvert_thread(ocfs2_get_lockres_osb(lockres)); | ||
2863 | break; | 2867 | break; |
2864 | case OCFS2_UNLOCK_DROP_LOCK: | 2868 | case OCFS2_UNLOCK_DROP_LOCK: |
2865 | lockres->l_level = DLM_LOCK_IV; | 2869 | lockres->l_level = DLM_LOCK_IV; |
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h index ad5c24a29edd..077384135f4e 100644 --- a/fs/ocfs2/ocfs2.h +++ b/fs/ocfs2/ocfs2.h | |||
@@ -210,6 +210,7 @@ struct ocfs2_journal; | |||
210 | struct ocfs2_slot_info; | 210 | struct ocfs2_slot_info; |
211 | struct ocfs2_recovery_map; | 211 | struct ocfs2_recovery_map; |
212 | struct ocfs2_quota_recovery; | 212 | struct ocfs2_quota_recovery; |
213 | struct ocfs2_dentry_lock; | ||
213 | struct ocfs2_super | 214 | struct ocfs2_super |
214 | { | 215 | { |
215 | struct task_struct *commit_task; | 216 | struct task_struct *commit_task; |
@@ -325,6 +326,11 @@ struct ocfs2_super | |||
325 | struct list_head blocked_lock_list; | 326 | struct list_head blocked_lock_list; |
326 | unsigned long blocked_lock_count; | 327 | unsigned long blocked_lock_count; |
327 | 328 | ||
329 | /* List of dentry locks to release. Anyone can add locks to | ||
330 | * the list, ocfs2_wq processes the list */ | ||
331 | struct ocfs2_dentry_lock *dentry_lock_list; | ||
332 | struct work_struct dentry_lock_work; | ||
333 | |||
328 | wait_queue_head_t osb_mount_event; | 334 | wait_queue_head_t osb_mount_event; |
329 | 335 | ||
330 | /* Truncate log info */ | 336 | /* Truncate log info */ |
diff --git a/fs/ocfs2/quota_global.c b/fs/ocfs2/quota_global.c index f4efa89baee5..1ed0f7c86869 100644 --- a/fs/ocfs2/quota_global.c +++ b/fs/ocfs2/quota_global.c | |||
@@ -754,7 +754,9 @@ static int ocfs2_mark_dquot_dirty(struct dquot *dquot) | |||
754 | if (dquot->dq_flags & mask) | 754 | if (dquot->dq_flags & mask) |
755 | sync = 1; | 755 | sync = 1; |
756 | spin_unlock(&dq_data_lock); | 756 | spin_unlock(&dq_data_lock); |
757 | if (!sync) { | 757 | /* This is a slight hack but we can't afford getting global quota |
758 | * lock if we already have a transaction started. */ | ||
759 | if (!sync || journal_current_handle()) { | ||
758 | status = ocfs2_write_dquot(dquot); | 760 | status = ocfs2_write_dquot(dquot); |
759 | goto out; | 761 | goto out; |
760 | } | 762 | } |
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index 43ed11345b59..b1cb38fbe807 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c | |||
@@ -1887,6 +1887,9 @@ static int ocfs2_initialize_super(struct super_block *sb, | |||
1887 | INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery); | 1887 | INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery); |
1888 | journal->j_state = OCFS2_JOURNAL_FREE; | 1888 | journal->j_state = OCFS2_JOURNAL_FREE; |
1889 | 1889 | ||
1890 | INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes); | ||
1891 | osb->dentry_lock_list = NULL; | ||
1892 | |||
1890 | /* get some pseudo constants for clustersize bits */ | 1893 | /* get some pseudo constants for clustersize bits */ |
1891 | osb->s_clustersize_bits = | 1894 | osb->s_clustersize_bits = |
1892 | le32_to_cpu(di->id2.i_super.s_clustersize_bits); | 1895 | le32_to_cpu(di->id2.i_super.s_clustersize_bits); |
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index e1d638af6ac3..915039fffe6e 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c | |||
@@ -4729,13 +4729,6 @@ static int ocfs2_xattr_bucket_value_truncate(struct inode *inode, | |||
4729 | vb.vb_xv = (struct ocfs2_xattr_value_root *) | 4729 | vb.vb_xv = (struct ocfs2_xattr_value_root *) |
4730 | (vb.vb_bh->b_data + offset % blocksize); | 4730 | (vb.vb_bh->b_data + offset % blocksize); |
4731 | 4731 | ||
4732 | ret = ocfs2_xattr_bucket_journal_access(ctxt->handle, bucket, | ||
4733 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
4734 | if (ret) { | ||
4735 | mlog_errno(ret); | ||
4736 | goto out; | ||
4737 | } | ||
4738 | |||
4739 | /* | 4732 | /* |
4740 | * From here on out we have to dirty the bucket. The generic | 4733 | * From here on out we have to dirty the bucket. The generic |
4741 | * value calls only modify one of the bucket's bhs, but we need | 4734 | * value calls only modify one of the bucket's bhs, but we need |
@@ -4748,12 +4741,18 @@ static int ocfs2_xattr_bucket_value_truncate(struct inode *inode, | |||
4748 | ret = ocfs2_xattr_value_truncate(inode, &vb, len, ctxt); | 4741 | ret = ocfs2_xattr_value_truncate(inode, &vb, len, ctxt); |
4749 | if (ret) { | 4742 | if (ret) { |
4750 | mlog_errno(ret); | 4743 | mlog_errno(ret); |
4751 | goto out_dirty; | 4744 | goto out; |
4745 | } | ||
4746 | |||
4747 | ret = ocfs2_xattr_bucket_journal_access(ctxt->handle, bucket, | ||
4748 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
4749 | if (ret) { | ||
4750 | mlog_errno(ret); | ||
4751 | goto out; | ||
4752 | } | 4752 | } |
4753 | 4753 | ||
4754 | xe->xe_value_size = cpu_to_le64(len); | 4754 | xe->xe_value_size = cpu_to_le64(len); |
4755 | 4755 | ||
4756 | out_dirty: | ||
4757 | ocfs2_xattr_bucket_journal_dirty(ctxt->handle, bucket); | 4756 | ocfs2_xattr_bucket_journal_dirty(ctxt->handle, bucket); |
4758 | 4757 | ||
4759 | out: | 4758 | out: |
diff --git a/fs/seq_file.c b/fs/seq_file.c index b569ff1c4dc8..5267098532bf 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c | |||
@@ -54,6 +54,64 @@ int seq_open(struct file *file, const struct seq_operations *op) | |||
54 | } | 54 | } |
55 | EXPORT_SYMBOL(seq_open); | 55 | EXPORT_SYMBOL(seq_open); |
56 | 56 | ||
57 | static int traverse(struct seq_file *m, loff_t offset) | ||
58 | { | ||
59 | loff_t pos = 0, index; | ||
60 | int error = 0; | ||
61 | void *p; | ||
62 | |||
63 | m->version = 0; | ||
64 | index = 0; | ||
65 | m->count = m->from = 0; | ||
66 | if (!offset) { | ||
67 | m->index = index; | ||
68 | return 0; | ||
69 | } | ||
70 | if (!m->buf) { | ||
71 | m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL); | ||
72 | if (!m->buf) | ||
73 | return -ENOMEM; | ||
74 | } | ||
75 | p = m->op->start(m, &index); | ||
76 | while (p) { | ||
77 | error = PTR_ERR(p); | ||
78 | if (IS_ERR(p)) | ||
79 | break; | ||
80 | error = m->op->show(m, p); | ||
81 | if (error < 0) | ||
82 | break; | ||
83 | if (unlikely(error)) { | ||
84 | error = 0; | ||
85 | m->count = 0; | ||
86 | } | ||
87 | if (m->count == m->size) | ||
88 | goto Eoverflow; | ||
89 | if (pos + m->count > offset) { | ||
90 | m->from = offset - pos; | ||
91 | m->count -= m->from; | ||
92 | m->index = index; | ||
93 | break; | ||
94 | } | ||
95 | pos += m->count; | ||
96 | m->count = 0; | ||
97 | if (pos == offset) { | ||
98 | index++; | ||
99 | m->index = index; | ||
100 | break; | ||
101 | } | ||
102 | p = m->op->next(m, p, &index); | ||
103 | } | ||
104 | m->op->stop(m, p); | ||
105 | m->index = index; | ||
106 | return error; | ||
107 | |||
108 | Eoverflow: | ||
109 | m->op->stop(m, p); | ||
110 | kfree(m->buf); | ||
111 | m->buf = kmalloc(m->size <<= 1, GFP_KERNEL); | ||
112 | return !m->buf ? -ENOMEM : -EAGAIN; | ||
113 | } | ||
114 | |||
57 | /** | 115 | /** |
58 | * seq_read - ->read() method for sequential files. | 116 | * seq_read - ->read() method for sequential files. |
59 | * @file: the file to read from | 117 | * @file: the file to read from |
@@ -186,63 +244,6 @@ Efault: | |||
186 | } | 244 | } |
187 | EXPORT_SYMBOL(seq_read); | 245 | EXPORT_SYMBOL(seq_read); |
188 | 246 | ||
189 | static int traverse(struct seq_file *m, loff_t offset) | ||
190 | { | ||
191 | loff_t pos = 0, index; | ||
192 | int error = 0; | ||
193 | void *p; | ||
194 | |||
195 | m->version = 0; | ||
196 | index = 0; | ||
197 | m->count = m->from = 0; | ||
198 | if (!offset) { | ||
199 | m->index = index; | ||
200 | return 0; | ||
201 | } | ||
202 | if (!m->buf) { | ||
203 | m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL); | ||
204 | if (!m->buf) | ||
205 | return -ENOMEM; | ||
206 | } | ||
207 | p = m->op->start(m, &index); | ||
208 | while (p) { | ||
209 | error = PTR_ERR(p); | ||
210 | if (IS_ERR(p)) | ||
211 | break; | ||
212 | error = m->op->show(m, p); | ||
213 | if (error < 0) | ||
214 | break; | ||
215 | if (unlikely(error)) { | ||
216 | error = 0; | ||
217 | m->count = 0; | ||
218 | } | ||
219 | if (m->count == m->size) | ||
220 | goto Eoverflow; | ||
221 | if (pos + m->count > offset) { | ||
222 | m->from = offset - pos; | ||
223 | m->count -= m->from; | ||
224 | m->index = index; | ||
225 | break; | ||
226 | } | ||
227 | pos += m->count; | ||
228 | m->count = 0; | ||
229 | if (pos == offset) { | ||
230 | index++; | ||
231 | m->index = index; | ||
232 | break; | ||
233 | } | ||
234 | p = m->op->next(m, p, &index); | ||
235 | } | ||
236 | m->op->stop(m, p); | ||
237 | return error; | ||
238 | |||
239 | Eoverflow: | ||
240 | m->op->stop(m, p); | ||
241 | kfree(m->buf); | ||
242 | m->buf = kmalloc(m->size <<= 1, GFP_KERNEL); | ||
243 | return !m->buf ? -ENOMEM : -EAGAIN; | ||
244 | } | ||
245 | |||
246 | /** | 247 | /** |
247 | * seq_lseek - ->llseek() method for sequential files. | 248 | * seq_lseek - ->llseek() method for sequential files. |
248 | * @file: the file in question | 249 | * @file: the file in question |
diff --git a/fs/ubifs/budget.c b/fs/ubifs/budget.c index 175f9c590b77..f393620890ee 100644 --- a/fs/ubifs/budget.c +++ b/fs/ubifs/budget.c | |||
@@ -689,7 +689,7 @@ long long ubifs_reported_space(const struct ubifs_info *c, long long free) | |||
689 | } | 689 | } |
690 | 690 | ||
691 | /** | 691 | /** |
692 | * ubifs_get_free_space - return amount of free space. | 692 | * ubifs_get_free_space_nolock - return amount of free space. |
693 | * @c: UBIFS file-system description object | 693 | * @c: UBIFS file-system description object |
694 | * | 694 | * |
695 | * This function calculates amount of free space to report to user-space. | 695 | * This function calculates amount of free space to report to user-space. |
@@ -704,16 +704,14 @@ long long ubifs_reported_space(const struct ubifs_info *c, long long free) | |||
704 | * traditional file-systems, because they have way less overhead than UBIFS. | 704 | * traditional file-systems, because they have way less overhead than UBIFS. |
705 | * So, to keep users happy, UBIFS tries to take the overhead into account. | 705 | * So, to keep users happy, UBIFS tries to take the overhead into account. |
706 | */ | 706 | */ |
707 | long long ubifs_get_free_space(struct ubifs_info *c) | 707 | long long ubifs_get_free_space_nolock(struct ubifs_info *c) |
708 | { | 708 | { |
709 | int min_idx_lebs, rsvd_idx_lebs, lebs; | 709 | int rsvd_idx_lebs, lebs; |
710 | long long available, outstanding, free; | 710 | long long available, outstanding, free; |
711 | 711 | ||
712 | spin_lock(&c->space_lock); | 712 | ubifs_assert(c->min_idx_lebs == ubifs_calc_min_idx_lebs(c)); |
713 | min_idx_lebs = c->min_idx_lebs; | ||
714 | ubifs_assert(min_idx_lebs == ubifs_calc_min_idx_lebs(c)); | ||
715 | outstanding = c->budg_data_growth + c->budg_dd_growth; | 713 | outstanding = c->budg_data_growth + c->budg_dd_growth; |
716 | available = ubifs_calc_available(c, min_idx_lebs); | 714 | available = ubifs_calc_available(c, c->min_idx_lebs); |
717 | 715 | ||
718 | /* | 716 | /* |
719 | * When reporting free space to user-space, UBIFS guarantees that it is | 717 | * When reporting free space to user-space, UBIFS guarantees that it is |
@@ -726,15 +724,14 @@ long long ubifs_get_free_space(struct ubifs_info *c) | |||
726 | * Note, the calculations below are similar to what we have in | 724 | * Note, the calculations below are similar to what we have in |
727 | * 'do_budget_space()', so refer there for comments. | 725 | * 'do_budget_space()', so refer there for comments. |
728 | */ | 726 | */ |
729 | if (min_idx_lebs > c->lst.idx_lebs) | 727 | if (c->min_idx_lebs > c->lst.idx_lebs) |
730 | rsvd_idx_lebs = min_idx_lebs - c->lst.idx_lebs; | 728 | rsvd_idx_lebs = c->min_idx_lebs - c->lst.idx_lebs; |
731 | else | 729 | else |
732 | rsvd_idx_lebs = 0; | 730 | rsvd_idx_lebs = 0; |
733 | lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt - | 731 | lebs = c->lst.empty_lebs + c->freeable_cnt + c->idx_gc_cnt - |
734 | c->lst.taken_empty_lebs; | 732 | c->lst.taken_empty_lebs; |
735 | lebs -= rsvd_idx_lebs; | 733 | lebs -= rsvd_idx_lebs; |
736 | available += lebs * (c->dark_wm - c->leb_overhead); | 734 | available += lebs * (c->dark_wm - c->leb_overhead); |
737 | spin_unlock(&c->space_lock); | ||
738 | 735 | ||
739 | if (available > outstanding) | 736 | if (available > outstanding) |
740 | free = ubifs_reported_space(c, available - outstanding); | 737 | free = ubifs_reported_space(c, available - outstanding); |
@@ -742,3 +739,21 @@ long long ubifs_get_free_space(struct ubifs_info *c) | |||
742 | free = 0; | 739 | free = 0; |
743 | return free; | 740 | return free; |
744 | } | 741 | } |
742 | |||
743 | /** | ||
744 | * ubifs_get_free_space - return amount of free space. | ||
745 | * @c: UBIFS file-system description object | ||
746 | * | ||
747 | * This function calculates and retuns amount of free space to report to | ||
748 | * user-space. | ||
749 | */ | ||
750 | long long ubifs_get_free_space(struct ubifs_info *c) | ||
751 | { | ||
752 | long long free; | ||
753 | |||
754 | spin_lock(&c->space_lock); | ||
755 | free = ubifs_get_free_space_nolock(c); | ||
756 | spin_unlock(&c->space_lock); | ||
757 | |||
758 | return free; | ||
759 | } | ||
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index 792c5a16c182..e975bd82f38b 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c | |||
@@ -620,9 +620,11 @@ void dbg_dump_budg(struct ubifs_info *c) | |||
620 | c->dark_wm, c->dead_wm, c->max_idx_node_sz); | 620 | c->dark_wm, c->dead_wm, c->max_idx_node_sz); |
621 | printk(KERN_DEBUG "\tgc_lnum %d, ihead_lnum %d\n", | 621 | printk(KERN_DEBUG "\tgc_lnum %d, ihead_lnum %d\n", |
622 | c->gc_lnum, c->ihead_lnum); | 622 | c->gc_lnum, c->ihead_lnum); |
623 | for (i = 0; i < c->jhead_cnt; i++) | 623 | /* If we are in R/O mode, journal heads do not exist */ |
624 | printk(KERN_DEBUG "\tjhead %d\t LEB %d\n", | 624 | if (c->jheads) |
625 | c->jheads[i].wbuf.jhead, c->jheads[i].wbuf.lnum); | 625 | for (i = 0; i < c->jhead_cnt; i++) |
626 | printk(KERN_DEBUG "\tjhead %d\t LEB %d\n", | ||
627 | c->jheads[i].wbuf.jhead, c->jheads[i].wbuf.lnum); | ||
626 | for (rb = rb_first(&c->buds); rb; rb = rb_next(rb)) { | 628 | for (rb = rb_first(&c->buds); rb; rb = rb_next(rb)) { |
627 | bud = rb_entry(rb, struct ubifs_bud, rb); | 629 | bud = rb_entry(rb, struct ubifs_bud, rb); |
628 | printk(KERN_DEBUG "\tbud LEB %d\n", bud->lnum); | 630 | printk(KERN_DEBUG "\tbud LEB %d\n", bud->lnum); |
@@ -637,10 +639,7 @@ void dbg_dump_budg(struct ubifs_info *c) | |||
637 | /* Print budgeting predictions */ | 639 | /* Print budgeting predictions */ |
638 | available = ubifs_calc_available(c, c->min_idx_lebs); | 640 | available = ubifs_calc_available(c, c->min_idx_lebs); |
639 | outstanding = c->budg_data_growth + c->budg_dd_growth; | 641 | outstanding = c->budg_data_growth + c->budg_dd_growth; |
640 | if (available > outstanding) | 642 | free = ubifs_get_free_space_nolock(c); |
641 | free = ubifs_reported_space(c, available - outstanding); | ||
642 | else | ||
643 | free = 0; | ||
644 | printk(KERN_DEBUG "Budgeting predictions:\n"); | 643 | printk(KERN_DEBUG "Budgeting predictions:\n"); |
645 | printk(KERN_DEBUG "\tavailable: %lld, outstanding %lld, free %lld\n", | 644 | printk(KERN_DEBUG "\tavailable: %lld, outstanding %lld, free %lld\n", |
646 | available, outstanding, free); | 645 | available, outstanding, free); |
@@ -861,6 +860,65 @@ void dbg_dump_index(struct ubifs_info *c) | |||
861 | } | 860 | } |
862 | 861 | ||
863 | /** | 862 | /** |
863 | * dbg_save_space_info - save information about flash space. | ||
864 | * @c: UBIFS file-system description object | ||
865 | * | ||
866 | * This function saves information about UBIFS free space, dirty space, etc, in | ||
867 | * order to check it later. | ||
868 | */ | ||
869 | void dbg_save_space_info(struct ubifs_info *c) | ||
870 | { | ||
871 | struct ubifs_debug_info *d = c->dbg; | ||
872 | |||
873 | ubifs_get_lp_stats(c, &d->saved_lst); | ||
874 | |||
875 | spin_lock(&c->space_lock); | ||
876 | d->saved_free = ubifs_get_free_space_nolock(c); | ||
877 | spin_unlock(&c->space_lock); | ||
878 | } | ||
879 | |||
880 | /** | ||
881 | * dbg_check_space_info - check flash space information. | ||
882 | * @c: UBIFS file-system description object | ||
883 | * | ||
884 | * This function compares current flash space information with the information | ||
885 | * which was saved when the 'dbg_save_space_info()' function was called. | ||
886 | * Returns zero if the information has not changed, and %-EINVAL it it has | ||
887 | * changed. | ||
888 | */ | ||
889 | int dbg_check_space_info(struct ubifs_info *c) | ||
890 | { | ||
891 | struct ubifs_debug_info *d = c->dbg; | ||
892 | struct ubifs_lp_stats lst; | ||
893 | long long avail, free; | ||
894 | |||
895 | spin_lock(&c->space_lock); | ||
896 | avail = ubifs_calc_available(c, c->min_idx_lebs); | ||
897 | spin_unlock(&c->space_lock); | ||
898 | free = ubifs_get_free_space(c); | ||
899 | |||
900 | if (free != d->saved_free) { | ||
901 | ubifs_err("free space changed from %lld to %lld", | ||
902 | d->saved_free, free); | ||
903 | goto out; | ||
904 | } | ||
905 | |||
906 | return 0; | ||
907 | |||
908 | out: | ||
909 | ubifs_msg("saved lprops statistics dump"); | ||
910 | dbg_dump_lstats(&d->saved_lst); | ||
911 | ubifs_get_lp_stats(c, &lst); | ||
912 | ubifs_msg("current lprops statistics dump"); | ||
913 | dbg_dump_lstats(&d->saved_lst); | ||
914 | spin_lock(&c->space_lock); | ||
915 | dbg_dump_budg(c); | ||
916 | spin_unlock(&c->space_lock); | ||
917 | dump_stack(); | ||
918 | return -EINVAL; | ||
919 | } | ||
920 | |||
921 | /** | ||
864 | * dbg_check_synced_i_size - check synchronized inode size. | 922 | * dbg_check_synced_i_size - check synchronized inode size. |
865 | * @inode: inode to check | 923 | * @inode: inode to check |
866 | * | 924 | * |
@@ -1349,7 +1407,7 @@ int dbg_check_tnc(struct ubifs_info *c, int extra) | |||
1349 | * @c: UBIFS file-system description object | 1407 | * @c: UBIFS file-system description object |
1350 | * @leaf_cb: called for each leaf node | 1408 | * @leaf_cb: called for each leaf node |
1351 | * @znode_cb: called for each indexing node | 1409 | * @znode_cb: called for each indexing node |
1352 | * @priv: private date which is passed to callbacks | 1410 | * @priv: private data which is passed to callbacks |
1353 | * | 1411 | * |
1354 | * This function walks the UBIFS index and calls the @leaf_cb for each leaf | 1412 | * This function walks the UBIFS index and calls the @leaf_cb for each leaf |
1355 | * node and @znode_cb for each indexing node. Returns zero in case of success | 1413 | * node and @znode_cb for each indexing node. Returns zero in case of success |
@@ -2409,7 +2467,7 @@ void ubifs_debugging_exit(struct ubifs_info *c) | |||
2409 | * Root directory for UBIFS stuff in debugfs. Contains sub-directories which | 2467 | * Root directory for UBIFS stuff in debugfs. Contains sub-directories which |
2410 | * contain the stuff specific to particular file-system mounts. | 2468 | * contain the stuff specific to particular file-system mounts. |
2411 | */ | 2469 | */ |
2412 | static struct dentry *debugfs_rootdir; | 2470 | static struct dentry *dfs_rootdir; |
2413 | 2471 | ||
2414 | /** | 2472 | /** |
2415 | * dbg_debugfs_init - initialize debugfs file-system. | 2473 | * dbg_debugfs_init - initialize debugfs file-system. |
@@ -2421,9 +2479,9 @@ static struct dentry *debugfs_rootdir; | |||
2421 | */ | 2479 | */ |
2422 | int dbg_debugfs_init(void) | 2480 | int dbg_debugfs_init(void) |
2423 | { | 2481 | { |
2424 | debugfs_rootdir = debugfs_create_dir("ubifs", NULL); | 2482 | dfs_rootdir = debugfs_create_dir("ubifs", NULL); |
2425 | if (IS_ERR(debugfs_rootdir)) { | 2483 | if (IS_ERR(dfs_rootdir)) { |
2426 | int err = PTR_ERR(debugfs_rootdir); | 2484 | int err = PTR_ERR(dfs_rootdir); |
2427 | ubifs_err("cannot create \"ubifs\" debugfs directory, " | 2485 | ubifs_err("cannot create \"ubifs\" debugfs directory, " |
2428 | "error %d\n", err); | 2486 | "error %d\n", err); |
2429 | return err; | 2487 | return err; |
@@ -2437,7 +2495,7 @@ int dbg_debugfs_init(void) | |||
2437 | */ | 2495 | */ |
2438 | void dbg_debugfs_exit(void) | 2496 | void dbg_debugfs_exit(void) |
2439 | { | 2497 | { |
2440 | debugfs_remove(debugfs_rootdir); | 2498 | debugfs_remove(dfs_rootdir); |
2441 | } | 2499 | } |
2442 | 2500 | ||
2443 | static int open_debugfs_file(struct inode *inode, struct file *file) | 2501 | static int open_debugfs_file(struct inode *inode, struct file *file) |
@@ -2452,13 +2510,13 @@ static ssize_t write_debugfs_file(struct file *file, const char __user *buf, | |||
2452 | struct ubifs_info *c = file->private_data; | 2510 | struct ubifs_info *c = file->private_data; |
2453 | struct ubifs_debug_info *d = c->dbg; | 2511 | struct ubifs_debug_info *d = c->dbg; |
2454 | 2512 | ||
2455 | if (file->f_path.dentry == d->dump_lprops) | 2513 | if (file->f_path.dentry == d->dfs_dump_lprops) |
2456 | dbg_dump_lprops(c); | 2514 | dbg_dump_lprops(c); |
2457 | else if (file->f_path.dentry == d->dump_budg) { | 2515 | else if (file->f_path.dentry == d->dfs_dump_budg) { |
2458 | spin_lock(&c->space_lock); | 2516 | spin_lock(&c->space_lock); |
2459 | dbg_dump_budg(c); | 2517 | dbg_dump_budg(c); |
2460 | spin_unlock(&c->space_lock); | 2518 | spin_unlock(&c->space_lock); |
2461 | } else if (file->f_path.dentry == d->dump_tnc) { | 2519 | } else if (file->f_path.dentry == d->dfs_dump_tnc) { |
2462 | mutex_lock(&c->tnc_mutex); | 2520 | mutex_lock(&c->tnc_mutex); |
2463 | dbg_dump_tnc(c); | 2521 | dbg_dump_tnc(c); |
2464 | mutex_unlock(&c->tnc_mutex); | 2522 | mutex_unlock(&c->tnc_mutex); |
@@ -2469,7 +2527,7 @@ static ssize_t write_debugfs_file(struct file *file, const char __user *buf, | |||
2469 | return count; | 2527 | return count; |
2470 | } | 2528 | } |
2471 | 2529 | ||
2472 | static const struct file_operations debugfs_fops = { | 2530 | static const struct file_operations dfs_fops = { |
2473 | .open = open_debugfs_file, | 2531 | .open = open_debugfs_file, |
2474 | .write = write_debugfs_file, | 2532 | .write = write_debugfs_file, |
2475 | .owner = THIS_MODULE, | 2533 | .owner = THIS_MODULE, |
@@ -2494,36 +2552,32 @@ int dbg_debugfs_init_fs(struct ubifs_info *c) | |||
2494 | struct dentry *dent; | 2552 | struct dentry *dent; |
2495 | struct ubifs_debug_info *d = c->dbg; | 2553 | struct ubifs_debug_info *d = c->dbg; |
2496 | 2554 | ||
2497 | sprintf(d->debugfs_dir_name, "ubi%d_%d", c->vi.ubi_num, c->vi.vol_id); | 2555 | sprintf(d->dfs_dir_name, "ubi%d_%d", c->vi.ubi_num, c->vi.vol_id); |
2498 | d->debugfs_dir = debugfs_create_dir(d->debugfs_dir_name, | 2556 | d->dfs_dir = debugfs_create_dir(d->dfs_dir_name, dfs_rootdir); |
2499 | debugfs_rootdir); | 2557 | if (IS_ERR(d->dfs_dir)) { |
2500 | if (IS_ERR(d->debugfs_dir)) { | 2558 | err = PTR_ERR(d->dfs_dir); |
2501 | err = PTR_ERR(d->debugfs_dir); | ||
2502 | ubifs_err("cannot create \"%s\" debugfs directory, error %d\n", | 2559 | ubifs_err("cannot create \"%s\" debugfs directory, error %d\n", |
2503 | d->debugfs_dir_name, err); | 2560 | d->dfs_dir_name, err); |
2504 | goto out; | 2561 | goto out; |
2505 | } | 2562 | } |
2506 | 2563 | ||
2507 | fname = "dump_lprops"; | 2564 | fname = "dump_lprops"; |
2508 | dent = debugfs_create_file(fname, S_IWUGO, d->debugfs_dir, c, | 2565 | dent = debugfs_create_file(fname, S_IWUGO, d->dfs_dir, c, &dfs_fops); |
2509 | &debugfs_fops); | ||
2510 | if (IS_ERR(dent)) | 2566 | if (IS_ERR(dent)) |
2511 | goto out_remove; | 2567 | goto out_remove; |
2512 | d->dump_lprops = dent; | 2568 | d->dfs_dump_lprops = dent; |
2513 | 2569 | ||
2514 | fname = "dump_budg"; | 2570 | fname = "dump_budg"; |
2515 | dent = debugfs_create_file(fname, S_IWUGO, d->debugfs_dir, c, | 2571 | dent = debugfs_create_file(fname, S_IWUGO, d->dfs_dir, c, &dfs_fops); |
2516 | &debugfs_fops); | ||
2517 | if (IS_ERR(dent)) | 2572 | if (IS_ERR(dent)) |
2518 | goto out_remove; | 2573 | goto out_remove; |
2519 | d->dump_budg = dent; | 2574 | d->dfs_dump_budg = dent; |
2520 | 2575 | ||
2521 | fname = "dump_tnc"; | 2576 | fname = "dump_tnc"; |
2522 | dent = debugfs_create_file(fname, S_IWUGO, d->debugfs_dir, c, | 2577 | dent = debugfs_create_file(fname, S_IWUGO, d->dfs_dir, c, &dfs_fops); |
2523 | &debugfs_fops); | ||
2524 | if (IS_ERR(dent)) | 2578 | if (IS_ERR(dent)) |
2525 | goto out_remove; | 2579 | goto out_remove; |
2526 | d->dump_tnc = dent; | 2580 | d->dfs_dump_tnc = dent; |
2527 | 2581 | ||
2528 | return 0; | 2582 | return 0; |
2529 | 2583 | ||
@@ -2531,7 +2585,7 @@ out_remove: | |||
2531 | err = PTR_ERR(dent); | 2585 | err = PTR_ERR(dent); |
2532 | ubifs_err("cannot create \"%s\" debugfs directory, error %d\n", | 2586 | ubifs_err("cannot create \"%s\" debugfs directory, error %d\n", |
2533 | fname, err); | 2587 | fname, err); |
2534 | debugfs_remove_recursive(d->debugfs_dir); | 2588 | debugfs_remove_recursive(d->dfs_dir); |
2535 | out: | 2589 | out: |
2536 | return err; | 2590 | return err; |
2537 | } | 2591 | } |
@@ -2542,7 +2596,7 @@ out: | |||
2542 | */ | 2596 | */ |
2543 | void dbg_debugfs_exit_fs(struct ubifs_info *c) | 2597 | void dbg_debugfs_exit_fs(struct ubifs_info *c) |
2544 | { | 2598 | { |
2545 | debugfs_remove_recursive(c->dbg->debugfs_dir); | 2599 | debugfs_remove_recursive(c->dbg->dfs_dir); |
2546 | } | 2600 | } |
2547 | 2601 | ||
2548 | #endif /* CONFIG_UBIFS_FS_DEBUG */ | 2602 | #endif /* CONFIG_UBIFS_FS_DEBUG */ |
diff --git a/fs/ubifs/debug.h b/fs/ubifs/debug.h index 9820d6999f7e..c1cd73b2e06e 100644 --- a/fs/ubifs/debug.h +++ b/fs/ubifs/debug.h | |||
@@ -41,15 +41,17 @@ | |||
41 | * @chk_lpt_wastage: used by LPT tree size checker | 41 | * @chk_lpt_wastage: used by LPT tree size checker |
42 | * @chk_lpt_lebs: used by LPT tree size checker | 42 | * @chk_lpt_lebs: used by LPT tree size checker |
43 | * @new_nhead_offs: used by LPT tree size checker | 43 | * @new_nhead_offs: used by LPT tree size checker |
44 | * @new_ihead_lnum: used by debugging to check ihead_lnum | 44 | * @new_ihead_lnum: used by debugging to check @c->ihead_lnum |
45 | * @new_ihead_offs: used by debugging to check ihead_offs | 45 | * @new_ihead_offs: used by debugging to check @c->ihead_offs |
46 | * | 46 | * |
47 | * debugfs_dir_name: name of debugfs directory containing this file-system's | 47 | * @saved_lst: saved lprops statistics (used by 'dbg_save_space_info()') |
48 | * files | 48 | * @saved_free: saved free space (used by 'dbg_save_space_info()') |
49 | * debugfs_dir: direntry object of the file-system debugfs directory | 49 | * |
50 | * dump_lprops: "dump lprops" debugfs knob | 50 | * dfs_dir_name: name of debugfs directory containing this file-system's files |
51 | * dump_budg: "dump budgeting information" debugfs knob | 51 | * dfs_dir: direntry object of the file-system debugfs directory |
52 | * dump_tnc: "dump TNC" debugfs knob | 52 | * dfs_dump_lprops: "dump lprops" debugfs knob |
53 | * dfs_dump_budg: "dump budgeting information" debugfs knob | ||
54 | * dfs_dump_tnc: "dump TNC" debugfs knob | ||
53 | */ | 55 | */ |
54 | struct ubifs_debug_info { | 56 | struct ubifs_debug_info { |
55 | void *buf; | 57 | void *buf; |
@@ -69,11 +71,14 @@ struct ubifs_debug_info { | |||
69 | int new_ihead_lnum; | 71 | int new_ihead_lnum; |
70 | int new_ihead_offs; | 72 | int new_ihead_offs; |
71 | 73 | ||
72 | char debugfs_dir_name[100]; | 74 | struct ubifs_lp_stats saved_lst; |
73 | struct dentry *debugfs_dir; | 75 | long long saved_free; |
74 | struct dentry *dump_lprops; | 76 | |
75 | struct dentry *dump_budg; | 77 | char dfs_dir_name[100]; |
76 | struct dentry *dump_tnc; | 78 | struct dentry *dfs_dir; |
79 | struct dentry *dfs_dump_lprops; | ||
80 | struct dentry *dfs_dump_budg; | ||
81 | struct dentry *dfs_dump_tnc; | ||
77 | }; | 82 | }; |
78 | 83 | ||
79 | #define ubifs_assert(expr) do { \ | 84 | #define ubifs_assert(expr) do { \ |
@@ -297,7 +302,8 @@ int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, | |||
297 | dbg_znode_callback znode_cb, void *priv); | 302 | dbg_znode_callback znode_cb, void *priv); |
298 | 303 | ||
299 | /* Checking functions */ | 304 | /* Checking functions */ |
300 | 305 | void dbg_save_space_info(struct ubifs_info *c); | |
306 | int dbg_check_space_info(struct ubifs_info *c); | ||
301 | int dbg_check_lprops(struct ubifs_info *c); | 307 | int dbg_check_lprops(struct ubifs_info *c); |
302 | int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot); | 308 | int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot); |
303 | int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot); | 309 | int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot); |
@@ -439,6 +445,8 @@ void dbg_debugfs_exit_fs(struct ubifs_info *c); | |||
439 | 445 | ||
440 | #define dbg_walk_index(c, leaf_cb, znode_cb, priv) 0 | 446 | #define dbg_walk_index(c, leaf_cb, znode_cb, priv) 0 |
441 | #define dbg_old_index_check_init(c, zroot) 0 | 447 | #define dbg_old_index_check_init(c, zroot) 0 |
448 | #define dbg_save_space_info(c) ({}) | ||
449 | #define dbg_check_space_info(c) 0 | ||
442 | #define dbg_check_old_index(c, zroot) 0 | 450 | #define dbg_check_old_index(c, zroot) 0 |
443 | #define dbg_check_cats(c) 0 | 451 | #define dbg_check_cats(c) 0 |
444 | #define dbg_check_ltab(c) 0 | 452 | #define dbg_check_ltab(c) 0 |
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index f448ab1f9c38..f55d523c52bb 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c | |||
@@ -482,30 +482,29 @@ static int ubifs_dir_release(struct inode *dir, struct file *file) | |||
482 | } | 482 | } |
483 | 483 | ||
484 | /** | 484 | /** |
485 | * lock_2_inodes - lock two UBIFS inodes. | 485 | * lock_2_inodes - a wrapper for locking two UBIFS inodes. |
486 | * @inode1: first inode | 486 | * @inode1: first inode |
487 | * @inode2: second inode | 487 | * @inode2: second inode |
488 | * | ||
489 | * We do not implement any tricks to guarantee strict lock ordering, because | ||
490 | * VFS has already done it for us on the @i_mutex. So this is just a simple | ||
491 | * wrapper function. | ||
488 | */ | 492 | */ |
489 | static void lock_2_inodes(struct inode *inode1, struct inode *inode2) | 493 | static void lock_2_inodes(struct inode *inode1, struct inode *inode2) |
490 | { | 494 | { |
491 | if (inode1->i_ino < inode2->i_ino) { | 495 | mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1); |
492 | mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_2); | 496 | mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2); |
493 | mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_3); | ||
494 | } else { | ||
495 | mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2); | ||
496 | mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_3); | ||
497 | } | ||
498 | } | 497 | } |
499 | 498 | ||
500 | /** | 499 | /** |
501 | * unlock_2_inodes - unlock two UBIFS inodes inodes. | 500 | * unlock_2_inodes - a wrapper for unlocking two UBIFS inodes. |
502 | * @inode1: first inode | 501 | * @inode1: first inode |
503 | * @inode2: second inode | 502 | * @inode2: second inode |
504 | */ | 503 | */ |
505 | static void unlock_2_inodes(struct inode *inode1, struct inode *inode2) | 504 | static void unlock_2_inodes(struct inode *inode1, struct inode *inode2) |
506 | { | 505 | { |
507 | mutex_unlock(&ubifs_inode(inode1)->ui_mutex); | ||
508 | mutex_unlock(&ubifs_inode(inode2)->ui_mutex); | 506 | mutex_unlock(&ubifs_inode(inode2)->ui_mutex); |
507 | mutex_unlock(&ubifs_inode(inode1)->ui_mutex); | ||
509 | } | 508 | } |
510 | 509 | ||
511 | static int ubifs_link(struct dentry *old_dentry, struct inode *dir, | 510 | static int ubifs_link(struct dentry *old_dentry, struct inode *dir, |
@@ -527,6 +526,8 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir, | |||
527 | dbg_gen("dent '%.*s' to ino %lu (nlink %d) in dir ino %lu", | 526 | dbg_gen("dent '%.*s' to ino %lu (nlink %d) in dir ino %lu", |
528 | dentry->d_name.len, dentry->d_name.name, inode->i_ino, | 527 | dentry->d_name.len, dentry->d_name.name, inode->i_ino, |
529 | inode->i_nlink, dir->i_ino); | 528 | inode->i_nlink, dir->i_ino); |
529 | ubifs_assert(mutex_is_locked(&dir->i_mutex)); | ||
530 | ubifs_assert(mutex_is_locked(&inode->i_mutex)); | ||
530 | err = dbg_check_synced_i_size(inode); | 531 | err = dbg_check_synced_i_size(inode); |
531 | if (err) | 532 | if (err) |
532 | return err; | 533 | return err; |
@@ -580,6 +581,8 @@ static int ubifs_unlink(struct inode *dir, struct dentry *dentry) | |||
580 | dbg_gen("dent '%.*s' from ino %lu (nlink %d) in dir ino %lu", | 581 | dbg_gen("dent '%.*s' from ino %lu (nlink %d) in dir ino %lu", |
581 | dentry->d_name.len, dentry->d_name.name, inode->i_ino, | 582 | dentry->d_name.len, dentry->d_name.name, inode->i_ino, |
582 | inode->i_nlink, dir->i_ino); | 583 | inode->i_nlink, dir->i_ino); |
584 | ubifs_assert(mutex_is_locked(&dir->i_mutex)); | ||
585 | ubifs_assert(mutex_is_locked(&inode->i_mutex)); | ||
583 | err = dbg_check_synced_i_size(inode); | 586 | err = dbg_check_synced_i_size(inode); |
584 | if (err) | 587 | if (err) |
585 | return err; | 588 | return err; |
@@ -667,7 +670,8 @@ static int ubifs_rmdir(struct inode *dir, struct dentry *dentry) | |||
667 | 670 | ||
668 | dbg_gen("directory '%.*s', ino %lu in dir ino %lu", dentry->d_name.len, | 671 | dbg_gen("directory '%.*s', ino %lu in dir ino %lu", dentry->d_name.len, |
669 | dentry->d_name.name, inode->i_ino, dir->i_ino); | 672 | dentry->d_name.name, inode->i_ino, dir->i_ino); |
670 | 673 | ubifs_assert(mutex_is_locked(&dir->i_mutex)); | |
674 | ubifs_assert(mutex_is_locked(&inode->i_mutex)); | ||
671 | err = check_dir_empty(c, dentry->d_inode); | 675 | err = check_dir_empty(c, dentry->d_inode); |
672 | if (err) | 676 | if (err) |
673 | return err; | 677 | return err; |
@@ -922,59 +926,30 @@ out_budg: | |||
922 | } | 926 | } |
923 | 927 | ||
924 | /** | 928 | /** |
925 | * lock_3_inodes - lock three UBIFS inodes for rename. | 929 | * lock_3_inodes - a wrapper for locking three UBIFS inodes. |
926 | * @inode1: first inode | 930 | * @inode1: first inode |
927 | * @inode2: second inode | 931 | * @inode2: second inode |
928 | * @inode3: third inode | 932 | * @inode3: third inode |
929 | * | 933 | * |
930 | * For 'ubifs_rename()', @inode1 may be the same as @inode2 whereas @inode3 may | 934 | * This function is used for 'ubifs_rename()' and @inode1 may be the same as |
931 | * be null. | 935 | * @inode2 whereas @inode3 may be %NULL. |
936 | * | ||
937 | * We do not implement any tricks to guarantee strict lock ordering, because | ||
938 | * VFS has already done it for us on the @i_mutex. So this is just a simple | ||
939 | * wrapper function. | ||
932 | */ | 940 | */ |
933 | static void lock_3_inodes(struct inode *inode1, struct inode *inode2, | 941 | static void lock_3_inodes(struct inode *inode1, struct inode *inode2, |
934 | struct inode *inode3) | 942 | struct inode *inode3) |
935 | { | 943 | { |
936 | struct inode *i1, *i2, *i3; | 944 | mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1); |
937 | 945 | if (inode2 != inode1) | |
938 | if (!inode3) { | 946 | mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2); |
939 | if (inode1 != inode2) { | 947 | if (inode3) |
940 | lock_2_inodes(inode1, inode2); | 948 | mutex_lock_nested(&ubifs_inode(inode3)->ui_mutex, WB_MUTEX_3); |
941 | return; | ||
942 | } | ||
943 | mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1); | ||
944 | return; | ||
945 | } | ||
946 | |||
947 | if (inode1 == inode2) { | ||
948 | lock_2_inodes(inode1, inode3); | ||
949 | return; | ||
950 | } | ||
951 | |||
952 | /* 3 different inodes */ | ||
953 | if (inode1 < inode2) { | ||
954 | i3 = inode2; | ||
955 | if (inode1 < inode3) { | ||
956 | i1 = inode1; | ||
957 | i2 = inode3; | ||
958 | } else { | ||
959 | i1 = inode3; | ||
960 | i2 = inode1; | ||
961 | } | ||
962 | } else { | ||
963 | i3 = inode1; | ||
964 | if (inode2 < inode3) { | ||
965 | i1 = inode2; | ||
966 | i2 = inode3; | ||
967 | } else { | ||
968 | i1 = inode3; | ||
969 | i2 = inode2; | ||
970 | } | ||
971 | } | ||
972 | mutex_lock_nested(&ubifs_inode(i1)->ui_mutex, WB_MUTEX_1); | ||
973 | lock_2_inodes(i2, i3); | ||
974 | } | 949 | } |
975 | 950 | ||
976 | /** | 951 | /** |
977 | * unlock_3_inodes - unlock three UBIFS inodes for rename. | 952 | * unlock_3_inodes - a wrapper for unlocking three UBIFS inodes for rename. |
978 | * @inode1: first inode | 953 | * @inode1: first inode |
979 | * @inode2: second inode | 954 | * @inode2: second inode |
980 | * @inode3: third inode | 955 | * @inode3: third inode |
@@ -982,11 +957,11 @@ static void lock_3_inodes(struct inode *inode1, struct inode *inode2, | |||
982 | static void unlock_3_inodes(struct inode *inode1, struct inode *inode2, | 957 | static void unlock_3_inodes(struct inode *inode1, struct inode *inode2, |
983 | struct inode *inode3) | 958 | struct inode *inode3) |
984 | { | 959 | { |
985 | mutex_unlock(&ubifs_inode(inode1)->ui_mutex); | ||
986 | if (inode1 != inode2) | ||
987 | mutex_unlock(&ubifs_inode(inode2)->ui_mutex); | ||
988 | if (inode3) | 960 | if (inode3) |
989 | mutex_unlock(&ubifs_inode(inode3)->ui_mutex); | 961 | mutex_unlock(&ubifs_inode(inode3)->ui_mutex); |
962 | if (inode1 != inode2) | ||
963 | mutex_unlock(&ubifs_inode(inode2)->ui_mutex); | ||
964 | mutex_unlock(&ubifs_inode(inode1)->ui_mutex); | ||
990 | } | 965 | } |
991 | 966 | ||
992 | static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry, | 967 | static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry, |
@@ -1020,6 +995,11 @@ static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1020 | "dir ino %lu", old_dentry->d_name.len, old_dentry->d_name.name, | 995 | "dir ino %lu", old_dentry->d_name.len, old_dentry->d_name.name, |
1021 | old_inode->i_ino, old_dir->i_ino, new_dentry->d_name.len, | 996 | old_inode->i_ino, old_dir->i_ino, new_dentry->d_name.len, |
1022 | new_dentry->d_name.name, new_dir->i_ino); | 997 | new_dentry->d_name.name, new_dir->i_ino); |
998 | ubifs_assert(mutex_is_locked(&old_dir->i_mutex)); | ||
999 | ubifs_assert(mutex_is_locked(&new_dir->i_mutex)); | ||
1000 | if (unlink) | ||
1001 | ubifs_assert(mutex_is_locked(&new_inode->i_mutex)); | ||
1002 | |||
1023 | 1003 | ||
1024 | if (unlink && is_dir) { | 1004 | if (unlink && is_dir) { |
1025 | err = check_dir_empty(c, new_inode); | 1005 | err = check_dir_empty(c, new_inode); |
@@ -1199,7 +1179,7 @@ int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry, | |||
1199 | return 0; | 1179 | return 0; |
1200 | } | 1180 | } |
1201 | 1181 | ||
1202 | struct inode_operations ubifs_dir_inode_operations = { | 1182 | const struct inode_operations ubifs_dir_inode_operations = { |
1203 | .lookup = ubifs_lookup, | 1183 | .lookup = ubifs_lookup, |
1204 | .create = ubifs_create, | 1184 | .create = ubifs_create, |
1205 | .link = ubifs_link, | 1185 | .link = ubifs_link, |
@@ -1219,7 +1199,7 @@ struct inode_operations ubifs_dir_inode_operations = { | |||
1219 | #endif | 1199 | #endif |
1220 | }; | 1200 | }; |
1221 | 1201 | ||
1222 | struct file_operations ubifs_dir_operations = { | 1202 | const struct file_operations ubifs_dir_operations = { |
1223 | .llseek = ubifs_dir_llseek, | 1203 | .llseek = ubifs_dir_llseek, |
1224 | .release = ubifs_dir_release, | 1204 | .release = ubifs_dir_release, |
1225 | .read = generic_read_dir, | 1205 | .read = generic_read_dir, |
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index bf37374567fa..93b6de51f261 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c | |||
@@ -432,7 +432,6 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, | |||
432 | int uninitialized_var(err), appending = !!(pos + len > inode->i_size); | 432 | int uninitialized_var(err), appending = !!(pos + len > inode->i_size); |
433 | struct page *page; | 433 | struct page *page; |
434 | 434 | ||
435 | |||
436 | ubifs_assert(ubifs_inode(inode)->ui_size == inode->i_size); | 435 | ubifs_assert(ubifs_inode(inode)->ui_size == inode->i_size); |
437 | 436 | ||
438 | if (unlikely(c->ro_media)) | 437 | if (unlikely(c->ro_media)) |
@@ -1541,7 +1540,7 @@ static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
1541 | return 0; | 1540 | return 0; |
1542 | } | 1541 | } |
1543 | 1542 | ||
1544 | struct address_space_operations ubifs_file_address_operations = { | 1543 | const struct address_space_operations ubifs_file_address_operations = { |
1545 | .readpage = ubifs_readpage, | 1544 | .readpage = ubifs_readpage, |
1546 | .writepage = ubifs_writepage, | 1545 | .writepage = ubifs_writepage, |
1547 | .write_begin = ubifs_write_begin, | 1546 | .write_begin = ubifs_write_begin, |
@@ -1551,7 +1550,7 @@ struct address_space_operations ubifs_file_address_operations = { | |||
1551 | .releasepage = ubifs_releasepage, | 1550 | .releasepage = ubifs_releasepage, |
1552 | }; | 1551 | }; |
1553 | 1552 | ||
1554 | struct inode_operations ubifs_file_inode_operations = { | 1553 | const struct inode_operations ubifs_file_inode_operations = { |
1555 | .setattr = ubifs_setattr, | 1554 | .setattr = ubifs_setattr, |
1556 | .getattr = ubifs_getattr, | 1555 | .getattr = ubifs_getattr, |
1557 | #ifdef CONFIG_UBIFS_FS_XATTR | 1556 | #ifdef CONFIG_UBIFS_FS_XATTR |
@@ -1562,14 +1561,14 @@ struct inode_operations ubifs_file_inode_operations = { | |||
1562 | #endif | 1561 | #endif |
1563 | }; | 1562 | }; |
1564 | 1563 | ||
1565 | struct inode_operations ubifs_symlink_inode_operations = { | 1564 | const struct inode_operations ubifs_symlink_inode_operations = { |
1566 | .readlink = generic_readlink, | 1565 | .readlink = generic_readlink, |
1567 | .follow_link = ubifs_follow_link, | 1566 | .follow_link = ubifs_follow_link, |
1568 | .setattr = ubifs_setattr, | 1567 | .setattr = ubifs_setattr, |
1569 | .getattr = ubifs_getattr, | 1568 | .getattr = ubifs_getattr, |
1570 | }; | 1569 | }; |
1571 | 1570 | ||
1572 | struct file_operations ubifs_file_operations = { | 1571 | const struct file_operations ubifs_file_operations = { |
1573 | .llseek = generic_file_llseek, | 1572 | .llseek = generic_file_llseek, |
1574 | .read = do_sync_read, | 1573 | .read = do_sync_read, |
1575 | .write = do_sync_write, | 1574 | .write = do_sync_write, |
diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c index 9832f9abe28e..a711d33b3d3e 100644 --- a/fs/ubifs/gc.c +++ b/fs/ubifs/gc.c | |||
@@ -31,6 +31,26 @@ | |||
31 | * to be reused. Garbage collection will cause the number of dirty index nodes | 31 | * to be reused. Garbage collection will cause the number of dirty index nodes |
32 | * to grow, however sufficient space is reserved for the index to ensure the | 32 | * to grow, however sufficient space is reserved for the index to ensure the |
33 | * commit will never run out of space. | 33 | * commit will never run out of space. |
34 | * | ||
35 | * Notes about dead watermark. At current UBIFS implementation we assume that | ||
36 | * LEBs which have less than @c->dead_wm bytes of free + dirty space are full | ||
37 | * and not worth garbage-collecting. The dead watermark is one min. I/O unit | ||
38 | * size, or min. UBIFS node size, depending on what is greater. Indeed, UBIFS | ||
39 | * Garbage Collector has to synchronize the GC head's write buffer before | ||
40 | * returning, so this is about wasting one min. I/O unit. However, UBIFS GC can | ||
41 | * actually reclaim even very small pieces of dirty space by garbage collecting | ||
42 | * enough dirty LEBs, but we do not bother doing this at this implementation. | ||
43 | * | ||
44 | * Notes about dark watermark. The results of GC work depends on how big are | ||
45 | * the UBIFS nodes GC deals with. Large nodes make GC waste more space. Indeed, | ||
46 | * if GC move data from LEB A to LEB B and nodes in LEB A are large, GC would | ||
47 | * have to waste large pieces of free space at the end of LEB B, because nodes | ||
48 | * from LEB A would not fit. And the worst situation is when all nodes are of | ||
49 | * maximum size. So dark watermark is the amount of free + dirty space in LEB | ||
50 | * which are guaranteed to be reclaimable. If LEB has less space, the GC migh | ||
51 | * be unable to reclaim it. So, LEBs with free + dirty greater than dark | ||
52 | * watermark are "good" LEBs from GC's point of few. The other LEBs are not so | ||
53 | * good, and GC takes extra care when moving them. | ||
34 | */ | 54 | */ |
35 | 55 | ||
36 | #include <linux/pagemap.h> | 56 | #include <linux/pagemap.h> |
@@ -381,7 +401,7 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp) | |||
381 | 401 | ||
382 | /* | 402 | /* |
383 | * Don't release the LEB until after the next commit, because | 403 | * Don't release the LEB until after the next commit, because |
384 | * it may contain date which is needed for recovery. So | 404 | * it may contain data which is needed for recovery. So |
385 | * although we freed this LEB, it will become usable only after | 405 | * although we freed this LEB, it will become usable only after |
386 | * the commit. | 406 | * the commit. |
387 | */ | 407 | */ |
@@ -810,8 +830,9 @@ out: | |||
810 | * ubifs_destroy_idx_gc - destroy idx_gc list. | 830 | * ubifs_destroy_idx_gc - destroy idx_gc list. |
811 | * @c: UBIFS file-system description object | 831 | * @c: UBIFS file-system description object |
812 | * | 832 | * |
813 | * This function destroys the idx_gc list. It is called when unmounting or | 833 | * This function destroys the @c->idx_gc list. It is called when unmounting |
814 | * remounting read-only so locks are not needed. | 834 | * so locks are not needed. Returns zero in case of success and a negative |
835 | * error code in case of failure. | ||
815 | */ | 836 | */ |
816 | void ubifs_destroy_idx_gc(struct ubifs_info *c) | 837 | void ubifs_destroy_idx_gc(struct ubifs_info *c) |
817 | { | 838 | { |
@@ -824,7 +845,6 @@ void ubifs_destroy_idx_gc(struct ubifs_info *c) | |||
824 | list_del(&idx_gc->list); | 845 | list_del(&idx_gc->list); |
825 | kfree(idx_gc); | 846 | kfree(idx_gc); |
826 | } | 847 | } |
827 | |||
828 | } | 848 | } |
829 | 849 | ||
830 | /** | 850 | /** |
diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c index 01682713af69..e8e632a1dcdf 100644 --- a/fs/ubifs/io.c +++ b/fs/ubifs/io.c | |||
@@ -29,7 +29,7 @@ | |||
29 | * would have been wasted for padding to the nearest minimal I/O unit boundary. | 29 | * would have been wasted for padding to the nearest minimal I/O unit boundary. |
30 | * Instead, data first goes to the write-buffer and is flushed when the | 30 | * Instead, data first goes to the write-buffer and is flushed when the |
31 | * buffer is full or when it is not used for some time (by timer). This is | 31 | * buffer is full or when it is not used for some time (by timer). This is |
32 | * similarto the mechanism is used by JFFS2. | 32 | * similar to the mechanism is used by JFFS2. |
33 | * | 33 | * |
34 | * Write-buffers are defined by 'struct ubifs_wbuf' objects and protected by | 34 | * Write-buffers are defined by 'struct ubifs_wbuf' objects and protected by |
35 | * mutexes defined inside these objects. Since sometimes upper-level code | 35 | * mutexes defined inside these objects. Since sometimes upper-level code |
@@ -75,7 +75,7 @@ void ubifs_ro_mode(struct ubifs_info *c, int err) | |||
75 | * @lnum: logical eraseblock number | 75 | * @lnum: logical eraseblock number |
76 | * @offs: offset within the logical eraseblock | 76 | * @offs: offset within the logical eraseblock |
77 | * @quiet: print no messages | 77 | * @quiet: print no messages |
78 | * @chk_crc: indicates whether to always check the CRC | 78 | * @must_chk_crc: indicates whether to always check the CRC |
79 | * | 79 | * |
80 | * This function checks node magic number and CRC checksum. This function also | 80 | * This function checks node magic number and CRC checksum. This function also |
81 | * validates node length to prevent UBIFS from becoming crazy when an attacker | 81 | * validates node length to prevent UBIFS from becoming crazy when an attacker |
@@ -83,11 +83,17 @@ void ubifs_ro_mode(struct ubifs_info *c, int err) | |||
83 | * node length in the common header could cause UBIFS to read memory outside of | 83 | * node length in the common header could cause UBIFS to read memory outside of |
84 | * allocated buffer when checking the CRC checksum. | 84 | * allocated buffer when checking the CRC checksum. |
85 | * | 85 | * |
86 | * This function returns zero in case of success %-EUCLEAN in case of bad CRC | 86 | * This function may skip data nodes CRC checking if @c->no_chk_data_crc is |
87 | * or magic. | 87 | * true, which is controlled by corresponding UBIFS mount option. However, if |
88 | * @must_chk_crc is true, then @c->no_chk_data_crc is ignored and CRC is | ||
89 | * checked. Similarly, if @c->always_chk_crc is true, @c->no_chk_data_crc is | ||
90 | * ignored and CRC is checked. | ||
91 | * | ||
92 | * This function returns zero in case of success and %-EUCLEAN in case of bad | ||
93 | * CRC or magic. | ||
88 | */ | 94 | */ |
89 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, | 95 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, |
90 | int offs, int quiet, int chk_crc) | 96 | int offs, int quiet, int must_chk_crc) |
91 | { | 97 | { |
92 | int err = -EINVAL, type, node_len; | 98 | int err = -EINVAL, type, node_len; |
93 | uint32_t crc, node_crc, magic; | 99 | uint32_t crc, node_crc, magic; |
@@ -123,9 +129,9 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, | |||
123 | node_len > c->ranges[type].max_len) | 129 | node_len > c->ranges[type].max_len) |
124 | goto out_len; | 130 | goto out_len; |
125 | 131 | ||
126 | if (!chk_crc && type == UBIFS_DATA_NODE && !c->always_chk_crc) | 132 | if (!must_chk_crc && type == UBIFS_DATA_NODE && !c->always_chk_crc && |
127 | if (c->no_chk_data_crc) | 133 | c->no_chk_data_crc) |
128 | return 0; | 134 | return 0; |
129 | 135 | ||
130 | crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); | 136 | crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); |
131 | node_crc = le32_to_cpu(ch->crc); | 137 | node_crc = le32_to_cpu(ch->crc); |
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c index 9b7c54e0cd2a..a11ca0958a23 100644 --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c | |||
@@ -208,7 +208,7 @@ again: | |||
208 | offs = 0; | 208 | offs = 0; |
209 | 209 | ||
210 | out: | 210 | out: |
211 | err = ubifs_wbuf_seek_nolock(wbuf, lnum, offs, UBI_SHORTTERM); | 211 | err = ubifs_wbuf_seek_nolock(wbuf, lnum, offs, wbuf->dtype); |
212 | if (err) | 212 | if (err) |
213 | goto out_unlock; | 213 | goto out_unlock; |
214 | 214 | ||
diff --git a/fs/ubifs/lprops.c b/fs/ubifs/lprops.c index dfd2bcece27a..4cdd284dea56 100644 --- a/fs/ubifs/lprops.c +++ b/fs/ubifs/lprops.c | |||
@@ -635,10 +635,10 @@ const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c, | |||
635 | * @c: UBIFS file-system description object | 635 | * @c: UBIFS file-system description object |
636 | * @st: return statistics | 636 | * @st: return statistics |
637 | */ | 637 | */ |
638 | void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *st) | 638 | void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst) |
639 | { | 639 | { |
640 | spin_lock(&c->space_lock); | 640 | spin_lock(&c->space_lock); |
641 | memcpy(st, &c->lst, sizeof(struct ubifs_lp_stats)); | 641 | memcpy(lst, &c->lst, sizeof(struct ubifs_lp_stats)); |
642 | spin_unlock(&c->space_lock); | 642 | spin_unlock(&c->space_lock); |
643 | } | 643 | } |
644 | 644 | ||
@@ -678,6 +678,9 @@ int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty, | |||
678 | 678 | ||
679 | out: | 679 | out: |
680 | ubifs_release_lprops(c); | 680 | ubifs_release_lprops(c); |
681 | if (err) | ||
682 | ubifs_err("cannot change properties of LEB %d, error %d", | ||
683 | lnum, err); | ||
681 | return err; | 684 | return err; |
682 | } | 685 | } |
683 | 686 | ||
@@ -714,6 +717,9 @@ int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty, | |||
714 | 717 | ||
715 | out: | 718 | out: |
716 | ubifs_release_lprops(c); | 719 | ubifs_release_lprops(c); |
720 | if (err) | ||
721 | ubifs_err("cannot update properties of LEB %d, error %d", | ||
722 | lnum, err); | ||
717 | return err; | 723 | return err; |
718 | } | 724 | } |
719 | 725 | ||
@@ -737,6 +743,8 @@ int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp) | |||
737 | lpp = ubifs_lpt_lookup(c, lnum); | 743 | lpp = ubifs_lpt_lookup(c, lnum); |
738 | if (IS_ERR(lpp)) { | 744 | if (IS_ERR(lpp)) { |
739 | err = PTR_ERR(lpp); | 745 | err = PTR_ERR(lpp); |
746 | ubifs_err("cannot read properties of LEB %d, error %d", | ||
747 | lnum, err); | ||
740 | goto out; | 748 | goto out; |
741 | } | 749 | } |
742 | 750 | ||
diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c index 96ca95707175..3216a1f277f8 100644 --- a/fs/ubifs/lpt_commit.c +++ b/fs/ubifs/lpt_commit.c | |||
@@ -556,23 +556,23 @@ no_space: | |||
556 | } | 556 | } |
557 | 557 | ||
558 | /** | 558 | /** |
559 | * next_pnode - find next pnode. | 559 | * next_pnode_to_dirty - find next pnode to dirty. |
560 | * @c: UBIFS file-system description object | 560 | * @c: UBIFS file-system description object |
561 | * @pnode: pnode | 561 | * @pnode: pnode |
562 | * | 562 | * |
563 | * This function returns the next pnode or %NULL if there are no more pnodes. | 563 | * This function returns the next pnode to dirty or %NULL if there are no more |
564 | * pnodes. Note that pnodes that have never been written (lnum == 0) are | ||
565 | * skipped. | ||
564 | */ | 566 | */ |
565 | static struct ubifs_pnode *next_pnode(struct ubifs_info *c, | 567 | static struct ubifs_pnode *next_pnode_to_dirty(struct ubifs_info *c, |
566 | struct ubifs_pnode *pnode) | 568 | struct ubifs_pnode *pnode) |
567 | { | 569 | { |
568 | struct ubifs_nnode *nnode; | 570 | struct ubifs_nnode *nnode; |
569 | int iip; | 571 | int iip; |
570 | 572 | ||
571 | /* Try to go right */ | 573 | /* Try to go right */ |
572 | nnode = pnode->parent; | 574 | nnode = pnode->parent; |
573 | iip = pnode->iip + 1; | 575 | for (iip = pnode->iip + 1; iip < UBIFS_LPT_FANOUT; iip++) { |
574 | if (iip < UBIFS_LPT_FANOUT) { | ||
575 | /* We assume here that LEB zero is never an LPT LEB */ | ||
576 | if (nnode->nbranch[iip].lnum) | 576 | if (nnode->nbranch[iip].lnum) |
577 | return ubifs_get_pnode(c, nnode, iip); | 577 | return ubifs_get_pnode(c, nnode, iip); |
578 | } | 578 | } |
@@ -583,8 +583,11 @@ static struct ubifs_pnode *next_pnode(struct ubifs_info *c, | |||
583 | nnode = nnode->parent; | 583 | nnode = nnode->parent; |
584 | if (!nnode) | 584 | if (!nnode) |
585 | return NULL; | 585 | return NULL; |
586 | /* We assume here that LEB zero is never an LPT LEB */ | 586 | for (; iip < UBIFS_LPT_FANOUT; iip++) { |
587 | } while (iip >= UBIFS_LPT_FANOUT || !nnode->nbranch[iip].lnum); | 587 | if (nnode->nbranch[iip].lnum) |
588 | break; | ||
589 | } | ||
590 | } while (iip >= UBIFS_LPT_FANOUT); | ||
588 | 591 | ||
589 | /* Go right */ | 592 | /* Go right */ |
590 | nnode = ubifs_get_nnode(c, nnode, iip); | 593 | nnode = ubifs_get_nnode(c, nnode, iip); |
@@ -593,12 +596,29 @@ static struct ubifs_pnode *next_pnode(struct ubifs_info *c, | |||
593 | 596 | ||
594 | /* Go down to level 1 */ | 597 | /* Go down to level 1 */ |
595 | while (nnode->level > 1) { | 598 | while (nnode->level > 1) { |
596 | nnode = ubifs_get_nnode(c, nnode, 0); | 599 | for (iip = 0; iip < UBIFS_LPT_FANOUT; iip++) { |
600 | if (nnode->nbranch[iip].lnum) | ||
601 | break; | ||
602 | } | ||
603 | if (iip >= UBIFS_LPT_FANOUT) { | ||
604 | /* | ||
605 | * Should not happen, but we need to keep going | ||
606 | * if it does. | ||
607 | */ | ||
608 | iip = 0; | ||
609 | } | ||
610 | nnode = ubifs_get_nnode(c, nnode, iip); | ||
597 | if (IS_ERR(nnode)) | 611 | if (IS_ERR(nnode)) |
598 | return (void *)nnode; | 612 | return (void *)nnode; |
599 | } | 613 | } |
600 | 614 | ||
601 | return ubifs_get_pnode(c, nnode, 0); | 615 | for (iip = 0; iip < UBIFS_LPT_FANOUT; iip++) |
616 | if (nnode->nbranch[iip].lnum) | ||
617 | break; | ||
618 | if (iip >= UBIFS_LPT_FANOUT) | ||
619 | /* Should not happen, but we need to keep going if it does */ | ||
620 | iip = 0; | ||
621 | return ubifs_get_pnode(c, nnode, iip); | ||
602 | } | 622 | } |
603 | 623 | ||
604 | /** | 624 | /** |
@@ -688,7 +708,7 @@ static int make_tree_dirty(struct ubifs_info *c) | |||
688 | pnode = pnode_lookup(c, 0); | 708 | pnode = pnode_lookup(c, 0); |
689 | while (pnode) { | 709 | while (pnode) { |
690 | do_make_pnode_dirty(c, pnode); | 710 | do_make_pnode_dirty(c, pnode); |
691 | pnode = next_pnode(c, pnode); | 711 | pnode = next_pnode_to_dirty(c, pnode); |
692 | if (IS_ERR(pnode)) | 712 | if (IS_ERR(pnode)) |
693 | return PTR_ERR(pnode); | 713 | return PTR_ERR(pnode); |
694 | } | 714 | } |
diff --git a/fs/ubifs/master.c b/fs/ubifs/master.c index 71d5493bf565..a88f33801b98 100644 --- a/fs/ubifs/master.c +++ b/fs/ubifs/master.c | |||
@@ -354,7 +354,7 @@ int ubifs_write_master(struct ubifs_info *c) | |||
354 | int err, lnum, offs, len; | 354 | int err, lnum, offs, len; |
355 | 355 | ||
356 | if (c->ro_media) | 356 | if (c->ro_media) |
357 | return -EINVAL; | 357 | return -EROFS; |
358 | 358 | ||
359 | lnum = UBIFS_MST_LNUM; | 359 | lnum = UBIFS_MST_LNUM; |
360 | offs = c->mst_offs + c->mst_node_alsz; | 360 | offs = c->mst_offs + c->mst_node_alsz; |
diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c index 9e6f403f170e..152a7b34a141 100644 --- a/fs/ubifs/orphan.c +++ b/fs/ubifs/orphan.c | |||
@@ -46,7 +46,7 @@ | |||
46 | * Orphans are accumulated in a rb-tree. When an inode's link count drops to | 46 | * Orphans are accumulated in a rb-tree. When an inode's link count drops to |
47 | * zero, the inode number is added to the rb-tree. It is removed from the tree | 47 | * zero, the inode number is added to the rb-tree. It is removed from the tree |
48 | * when the inode is deleted. Any new orphans that are in the orphan tree when | 48 | * when the inode is deleted. Any new orphans that are in the orphan tree when |
49 | * the commit is run, are written to the orphan area in 1 or more orph nodes. | 49 | * the commit is run, are written to the orphan area in 1 or more orphan nodes. |
50 | * If the orphan area is full, it is consolidated to make space. There is | 50 | * If the orphan area is full, it is consolidated to make space. There is |
51 | * always enough space because validation prevents the user from creating more | 51 | * always enough space because validation prevents the user from creating more |
52 | * than the maximum number of orphans allowed. | 52 | * than the maximum number of orphans allowed. |
@@ -231,7 +231,7 @@ static int tot_avail_orphs(struct ubifs_info *c) | |||
231 | } | 231 | } |
232 | 232 | ||
233 | /** | 233 | /** |
234 | * do_write_orph_node - write a node | 234 | * do_write_orph_node - write a node to the orphan head. |
235 | * @c: UBIFS file-system description object | 235 | * @c: UBIFS file-system description object |
236 | * @len: length of node | 236 | * @len: length of node |
237 | * @atomic: write atomically | 237 | * @atomic: write atomically |
@@ -264,11 +264,11 @@ static int do_write_orph_node(struct ubifs_info *c, int len, int atomic) | |||
264 | } | 264 | } |
265 | 265 | ||
266 | /** | 266 | /** |
267 | * write_orph_node - write an orph node | 267 | * write_orph_node - write an orphan node. |
268 | * @c: UBIFS file-system description object | 268 | * @c: UBIFS file-system description object |
269 | * @atomic: write atomically | 269 | * @atomic: write atomically |
270 | * | 270 | * |
271 | * This function builds an orph node from the cnext list and writes it to the | 271 | * This function builds an orphan node from the cnext list and writes it to the |
272 | * orphan head. On success, %0 is returned, otherwise a negative error code | 272 | * orphan head. On success, %0 is returned, otherwise a negative error code |
273 | * is returned. | 273 | * is returned. |
274 | */ | 274 | */ |
@@ -326,11 +326,11 @@ static int write_orph_node(struct ubifs_info *c, int atomic) | |||
326 | } | 326 | } |
327 | 327 | ||
328 | /** | 328 | /** |
329 | * write_orph_nodes - write orph nodes until there are no more to commit | 329 | * write_orph_nodes - write orphan nodes until there are no more to commit. |
330 | * @c: UBIFS file-system description object | 330 | * @c: UBIFS file-system description object |
331 | * @atomic: write atomically | 331 | * @atomic: write atomically |
332 | * | 332 | * |
333 | * This function writes orph nodes for all the orphans to commit. On success, | 333 | * This function writes orphan nodes for all the orphans to commit. On success, |
334 | * %0 is returned, otherwise a negative error code is returned. | 334 | * %0 is returned, otherwise a negative error code is returned. |
335 | */ | 335 | */ |
336 | static int write_orph_nodes(struct ubifs_info *c, int atomic) | 336 | static int write_orph_nodes(struct ubifs_info *c, int atomic) |
@@ -478,14 +478,14 @@ int ubifs_orphan_end_commit(struct ubifs_info *c) | |||
478 | } | 478 | } |
479 | 479 | ||
480 | /** | 480 | /** |
481 | * clear_orphans - erase all LEBs used for orphans. | 481 | * ubifs_clear_orphans - erase all LEBs used for orphans. |
482 | * @c: UBIFS file-system description object | 482 | * @c: UBIFS file-system description object |
483 | * | 483 | * |
484 | * If recovery is not required, then the orphans from the previous session | 484 | * If recovery is not required, then the orphans from the previous session |
485 | * are not needed. This function locates the LEBs used to record | 485 | * are not needed. This function locates the LEBs used to record |
486 | * orphans, and un-maps them. | 486 | * orphans, and un-maps them. |
487 | */ | 487 | */ |
488 | static int clear_orphans(struct ubifs_info *c) | 488 | int ubifs_clear_orphans(struct ubifs_info *c) |
489 | { | 489 | { |
490 | int lnum, err; | 490 | int lnum, err; |
491 | 491 | ||
@@ -547,9 +547,9 @@ static int insert_dead_orphan(struct ubifs_info *c, ino_t inum) | |||
547 | * do_kill_orphans - remove orphan inodes from the index. | 547 | * do_kill_orphans - remove orphan inodes from the index. |
548 | * @c: UBIFS file-system description object | 548 | * @c: UBIFS file-system description object |
549 | * @sleb: scanned LEB | 549 | * @sleb: scanned LEB |
550 | * @last_cmt_no: cmt_no of last orph node read is passed and returned here | 550 | * @last_cmt_no: cmt_no of last orphan node read is passed and returned here |
551 | * @outofdate: whether the LEB is out of date is returned here | 551 | * @outofdate: whether the LEB is out of date is returned here |
552 | * @last_flagged: whether the end orph node is encountered | 552 | * @last_flagged: whether the end orphan node is encountered |
553 | * | 553 | * |
554 | * This function is a helper to the 'kill_orphans()' function. It goes through | 554 | * This function is a helper to the 'kill_orphans()' function. It goes through |
555 | * every orphan node in a LEB and for every inode number recorded, removes | 555 | * every orphan node in a LEB and for every inode number recorded, removes |
@@ -580,8 +580,8 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb, | |||
580 | /* | 580 | /* |
581 | * The commit number on the master node may be less, because | 581 | * The commit number on the master node may be less, because |
582 | * of a failed commit. If there are several failed commits in a | 582 | * of a failed commit. If there are several failed commits in a |
583 | * row, the commit number written on orph nodes will continue to | 583 | * row, the commit number written on orphan nodes will continue |
584 | * increase (because the commit number is adjusted here) even | 584 | * to increase (because the commit number is adjusted here) even |
585 | * though the commit number on the master node stays the same | 585 | * though the commit number on the master node stays the same |
586 | * because the master node has not been re-written. | 586 | * because the master node has not been re-written. |
587 | */ | 587 | */ |
@@ -589,9 +589,9 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb, | |||
589 | c->cmt_no = cmt_no; | 589 | c->cmt_no = cmt_no; |
590 | if (cmt_no < *last_cmt_no && *last_flagged) { | 590 | if (cmt_no < *last_cmt_no && *last_flagged) { |
591 | /* | 591 | /* |
592 | * The last orph node had a higher commit number and was | 592 | * The last orphan node had a higher commit number and |
593 | * flagged as the last written for that commit number. | 593 | * was flagged as the last written for that commit |
594 | * That makes this orph node, out of date. | 594 | * number. That makes this orphan node, out of date. |
595 | */ | 595 | */ |
596 | if (!first) { | 596 | if (!first) { |
597 | ubifs_err("out of order commit number %llu in " | 597 | ubifs_err("out of order commit number %llu in " |
@@ -658,10 +658,10 @@ static int kill_orphans(struct ubifs_info *c) | |||
658 | /* | 658 | /* |
659 | * Orph nodes always start at c->orph_first and are written to each | 659 | * Orph nodes always start at c->orph_first and are written to each |
660 | * successive LEB in turn. Generally unused LEBs will have been unmapped | 660 | * successive LEB in turn. Generally unused LEBs will have been unmapped |
661 | * but may contain out of date orph nodes if the unmap didn't go | 661 | * but may contain out of date orphan nodes if the unmap didn't go |
662 | * through. In addition, the last orph node written for each commit is | 662 | * through. In addition, the last orphan node written for each commit is |
663 | * marked (top bit of orph->cmt_no is set to 1). It is possible that | 663 | * marked (top bit of orph->cmt_no is set to 1). It is possible that |
664 | * there are orph nodes from the next commit (i.e. the commit did not | 664 | * there are orphan nodes from the next commit (i.e. the commit did not |
665 | * complete successfully). In that case, no orphans will have been lost | 665 | * complete successfully). In that case, no orphans will have been lost |
666 | * due to the way that orphans are written, and any orphans added will | 666 | * due to the way that orphans are written, and any orphans added will |
667 | * be valid orphans anyway and so can be deleted. | 667 | * be valid orphans anyway and so can be deleted. |
@@ -718,7 +718,7 @@ int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only) | |||
718 | if (unclean) | 718 | if (unclean) |
719 | err = kill_orphans(c); | 719 | err = kill_orphans(c); |
720 | else if (!read_only) | 720 | else if (!read_only) |
721 | err = clear_orphans(c); | 721 | err = ubifs_clear_orphans(c); |
722 | 722 | ||
723 | return err; | 723 | return err; |
724 | } | 724 | } |
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 89556ee72518..1182b66a5491 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c | |||
@@ -397,6 +397,7 @@ static int ubifs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
397 | buf->f_namelen = UBIFS_MAX_NLEN; | 397 | buf->f_namelen = UBIFS_MAX_NLEN; |
398 | buf->f_fsid.val[0] = le32_to_cpu(uuid[0]) ^ le32_to_cpu(uuid[2]); | 398 | buf->f_fsid.val[0] = le32_to_cpu(uuid[0]) ^ le32_to_cpu(uuid[2]); |
399 | buf->f_fsid.val[1] = le32_to_cpu(uuid[1]) ^ le32_to_cpu(uuid[3]); | 399 | buf->f_fsid.val[1] = le32_to_cpu(uuid[1]) ^ le32_to_cpu(uuid[3]); |
400 | ubifs_assert(buf->f_bfree <= c->block_cnt); | ||
400 | return 0; | 401 | return 0; |
401 | } | 402 | } |
402 | 403 | ||
@@ -432,33 +433,24 @@ static int ubifs_sync_fs(struct super_block *sb, int wait) | |||
432 | int i, err; | 433 | int i, err; |
433 | struct ubifs_info *c = sb->s_fs_info; | 434 | struct ubifs_info *c = sb->s_fs_info; |
434 | struct writeback_control wbc = { | 435 | struct writeback_control wbc = { |
435 | .sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_NONE, | 436 | .sync_mode = WB_SYNC_ALL, |
436 | .range_start = 0, | 437 | .range_start = 0, |
437 | .range_end = LLONG_MAX, | 438 | .range_end = LLONG_MAX, |
438 | .nr_to_write = LONG_MAX, | 439 | .nr_to_write = LONG_MAX, |
439 | }; | 440 | }; |
440 | 441 | ||
441 | /* | 442 | /* |
442 | * Note by akpm about WB_SYNC_NONE used above: zero @wait is just an | 443 | * Zero @wait is just an advisory thing to help the file system shove |
443 | * advisory thing to help the file system shove lots of data into the | 444 | * lots of data into the queues, and there will be the second |
444 | * queues. If some gets missed then it'll be picked up on the second | ||
445 | * '->sync_fs()' call, with non-zero @wait. | 445 | * '->sync_fs()' call, with non-zero @wait. |
446 | */ | 446 | */ |
447 | if (!wait) | ||
448 | return 0; | ||
447 | 449 | ||
448 | if (sb->s_flags & MS_RDONLY) | 450 | if (sb->s_flags & MS_RDONLY) |
449 | return 0; | 451 | return 0; |
450 | 452 | ||
451 | /* | 453 | /* |
452 | * Synchronize write buffers, because 'ubifs_run_commit()' does not | ||
453 | * do this if it waits for an already running commit. | ||
454 | */ | ||
455 | for (i = 0; i < c->jhead_cnt; i++) { | ||
456 | err = ubifs_wbuf_sync(&c->jheads[i].wbuf); | ||
457 | if (err) | ||
458 | return err; | ||
459 | } | ||
460 | |||
461 | /* | ||
462 | * VFS calls '->sync_fs()' before synchronizing all dirty inodes and | 454 | * VFS calls '->sync_fs()' before synchronizing all dirty inodes and |
463 | * pages, so synchronize them first, then commit the journal. Strictly | 455 | * pages, so synchronize them first, then commit the journal. Strictly |
464 | * speaking, it is not necessary to commit the journal here, | 456 | * speaking, it is not necessary to commit the journal here, |
@@ -469,6 +461,16 @@ static int ubifs_sync_fs(struct super_block *sb, int wait) | |||
469 | */ | 461 | */ |
470 | generic_sync_sb_inodes(sb, &wbc); | 462 | generic_sync_sb_inodes(sb, &wbc); |
471 | 463 | ||
464 | /* | ||
465 | * Synchronize write buffers, because 'ubifs_run_commit()' does not | ||
466 | * do this if it waits for an already running commit. | ||
467 | */ | ||
468 | for (i = 0; i < c->jhead_cnt; i++) { | ||
469 | err = ubifs_wbuf_sync(&c->jheads[i].wbuf); | ||
470 | if (err) | ||
471 | return err; | ||
472 | } | ||
473 | |||
472 | err = ubifs_run_commit(c); | 474 | err = ubifs_run_commit(c); |
473 | if (err) | 475 | if (err) |
474 | return err; | 476 | return err; |
@@ -572,15 +574,8 @@ static int init_constants_early(struct ubifs_info *c) | |||
572 | c->ranges[UBIFS_IDX_NODE].max_len = INT_MAX; | 574 | c->ranges[UBIFS_IDX_NODE].max_len = INT_MAX; |
573 | 575 | ||
574 | /* | 576 | /* |
575 | * Initialize dead and dark LEB space watermarks. | 577 | * Initialize dead and dark LEB space watermarks. See gc.c for comments |
576 | * | 578 | * about these values. |
577 | * Dead space is the space which cannot be used. Its watermark is | ||
578 | * equivalent to min. I/O unit or minimum node size if it is greater | ||
579 | * then min. I/O unit. | ||
580 | * | ||
581 | * Dark space is the space which might be used, or might not, depending | ||
582 | * on which node should be written to the LEB. Its watermark is | ||
583 | * equivalent to maximum UBIFS node size. | ||
584 | */ | 579 | */ |
585 | c->dead_wm = ALIGN(MIN_WRITE_SZ, c->min_io_size); | 580 | c->dead_wm = ALIGN(MIN_WRITE_SZ, c->min_io_size); |
586 | c->dark_wm = ALIGN(UBIFS_MAX_NODE_SZ, c->min_io_size); | 581 | c->dark_wm = ALIGN(UBIFS_MAX_NODE_SZ, c->min_io_size); |
@@ -741,12 +736,12 @@ static void init_constants_master(struct ubifs_info *c) | |||
741 | * take_gc_lnum - reserve GC LEB. | 736 | * take_gc_lnum - reserve GC LEB. |
742 | * @c: UBIFS file-system description object | 737 | * @c: UBIFS file-system description object |
743 | * | 738 | * |
744 | * This function ensures that the LEB reserved for garbage collection is | 739 | * This function ensures that the LEB reserved for garbage collection is marked |
745 | * unmapped and is marked as "taken" in lprops. We also have to set free space | 740 | * as "taken" in lprops. We also have to set free space to LEB size and dirty |
746 | * to LEB size and dirty space to zero, because lprops may contain out-of-date | 741 | * space to zero, because lprops may contain out-of-date information if the |
747 | * information if the file-system was un-mounted before it has been committed. | 742 | * file-system was un-mounted before it has been committed. This function |
748 | * This function returns zero in case of success and a negative error code in | 743 | * returns zero in case of success and a negative error code in case of |
749 | * case of failure. | 744 | * failure. |
750 | */ | 745 | */ |
751 | static int take_gc_lnum(struct ubifs_info *c) | 746 | static int take_gc_lnum(struct ubifs_info *c) |
752 | { | 747 | { |
@@ -757,10 +752,6 @@ static int take_gc_lnum(struct ubifs_info *c) | |||
757 | return -EINVAL; | 752 | return -EINVAL; |
758 | } | 753 | } |
759 | 754 | ||
760 | err = ubifs_leb_unmap(c, c->gc_lnum); | ||
761 | if (err) | ||
762 | return err; | ||
763 | |||
764 | /* And we have to tell lprops that this LEB is taken */ | 755 | /* And we have to tell lprops that this LEB is taken */ |
765 | err = ubifs_change_one_lp(c, c->gc_lnum, c->leb_size, 0, | 756 | err = ubifs_change_one_lp(c, c->gc_lnum, c->leb_size, 0, |
766 | LPROPS_TAKEN, 0, 0); | 757 | LPROPS_TAKEN, 0, 0); |
@@ -966,13 +957,16 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options, | |||
966 | 957 | ||
967 | token = match_token(p, tokens, args); | 958 | token = match_token(p, tokens, args); |
968 | switch (token) { | 959 | switch (token) { |
960 | /* | ||
961 | * %Opt_fast_unmount and %Opt_norm_unmount options are ignored. | ||
962 | * We accepte them in order to be backware-compatible. But this | ||
963 | * should be removed at some point. | ||
964 | */ | ||
969 | case Opt_fast_unmount: | 965 | case Opt_fast_unmount: |
970 | c->mount_opts.unmount_mode = 2; | 966 | c->mount_opts.unmount_mode = 2; |
971 | c->fast_unmount = 1; | ||
972 | break; | 967 | break; |
973 | case Opt_norm_unmount: | 968 | case Opt_norm_unmount: |
974 | c->mount_opts.unmount_mode = 1; | 969 | c->mount_opts.unmount_mode = 1; |
975 | c->fast_unmount = 0; | ||
976 | break; | 970 | break; |
977 | case Opt_bulk_read: | 971 | case Opt_bulk_read: |
978 | c->mount_opts.bulk_read = 2; | 972 | c->mount_opts.bulk_read = 2; |
@@ -1094,12 +1088,7 @@ static int check_free_space(struct ubifs_info *c) | |||
1094 | ubifs_err("insufficient free space to mount in read/write mode"); | 1088 | ubifs_err("insufficient free space to mount in read/write mode"); |
1095 | dbg_dump_budg(c); | 1089 | dbg_dump_budg(c); |
1096 | dbg_dump_lprops(c); | 1090 | dbg_dump_lprops(c); |
1097 | /* | 1091 | return -ENOSPC; |
1098 | * We return %-EINVAL instead of %-ENOSPC because it seems to | ||
1099 | * be the closest error code mentioned in the mount function | ||
1100 | * documentation. | ||
1101 | */ | ||
1102 | return -EINVAL; | ||
1103 | } | 1092 | } |
1104 | return 0; | 1093 | return 0; |
1105 | } | 1094 | } |
@@ -1286,10 +1275,19 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1286 | if (err) | 1275 | if (err) |
1287 | goto out_orphans; | 1276 | goto out_orphans; |
1288 | err = ubifs_rcvry_gc_commit(c); | 1277 | err = ubifs_rcvry_gc_commit(c); |
1289 | } else | 1278 | } else { |
1290 | err = take_gc_lnum(c); | 1279 | err = take_gc_lnum(c); |
1291 | if (err) | 1280 | if (err) |
1292 | goto out_orphans; | 1281 | goto out_orphans; |
1282 | |||
1283 | /* | ||
1284 | * GC LEB may contain garbage if there was an unclean | ||
1285 | * reboot, and it should be un-mapped. | ||
1286 | */ | ||
1287 | err = ubifs_leb_unmap(c, c->gc_lnum); | ||
1288 | if (err) | ||
1289 | return err; | ||
1290 | } | ||
1293 | 1291 | ||
1294 | err = dbg_check_lprops(c); | 1292 | err = dbg_check_lprops(c); |
1295 | if (err) | 1293 | if (err) |
@@ -1298,6 +1296,16 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1298 | err = ubifs_recover_size(c); | 1296 | err = ubifs_recover_size(c); |
1299 | if (err) | 1297 | if (err) |
1300 | goto out_orphans; | 1298 | goto out_orphans; |
1299 | } else { | ||
1300 | /* | ||
1301 | * Even if we mount read-only, we have to set space in GC LEB | ||
1302 | * to proper value because this affects UBIFS free space | ||
1303 | * reporting. We do not want to have a situation when | ||
1304 | * re-mounting from R/O to R/W changes amount of free space. | ||
1305 | */ | ||
1306 | err = take_gc_lnum(c); | ||
1307 | if (err) | ||
1308 | goto out_orphans; | ||
1301 | } | 1309 | } |
1302 | 1310 | ||
1303 | spin_lock(&ubifs_infos_lock); | 1311 | spin_lock(&ubifs_infos_lock); |
@@ -1310,14 +1318,17 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1310 | else { | 1318 | else { |
1311 | c->need_recovery = 0; | 1319 | c->need_recovery = 0; |
1312 | ubifs_msg("recovery completed"); | 1320 | ubifs_msg("recovery completed"); |
1321 | /* GC LEB has to be empty and taken at this point */ | ||
1322 | ubifs_assert(c->lst.taken_empty_lebs == 1); | ||
1313 | } | 1323 | } |
1314 | } | 1324 | } else |
1325 | ubifs_assert(c->lst.taken_empty_lebs == 1); | ||
1315 | 1326 | ||
1316 | err = dbg_debugfs_init_fs(c); | 1327 | err = dbg_check_filesystem(c); |
1317 | if (err) | 1328 | if (err) |
1318 | goto out_infos; | 1329 | goto out_infos; |
1319 | 1330 | ||
1320 | err = dbg_check_filesystem(c); | 1331 | err = dbg_debugfs_init_fs(c); |
1321 | if (err) | 1332 | if (err) |
1322 | goto out_infos; | 1333 | goto out_infos; |
1323 | 1334 | ||
@@ -1351,7 +1362,6 @@ static int mount_ubifs(struct ubifs_info *c) | |||
1351 | c->uuid[4], c->uuid[5], c->uuid[6], c->uuid[7], | 1362 | c->uuid[4], c->uuid[5], c->uuid[6], c->uuid[7], |
1352 | c->uuid[8], c->uuid[9], c->uuid[10], c->uuid[11], | 1363 | c->uuid[8], c->uuid[9], c->uuid[10], c->uuid[11], |
1353 | c->uuid[12], c->uuid[13], c->uuid[14], c->uuid[15]); | 1364 | c->uuid[12], c->uuid[13], c->uuid[14], c->uuid[15]); |
1354 | dbg_msg("fast unmount: %d", c->fast_unmount); | ||
1355 | dbg_msg("big_lpt %d", c->big_lpt); | 1365 | dbg_msg("big_lpt %d", c->big_lpt); |
1356 | dbg_msg("log LEBs: %d (%d - %d)", | 1366 | dbg_msg("log LEBs: %d (%d - %d)", |
1357 | c->log_lebs, UBIFS_LOG_LNUM, c->log_last); | 1367 | c->log_lebs, UBIFS_LOG_LNUM, c->log_last); |
@@ -1475,10 +1485,8 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1475 | { | 1485 | { |
1476 | int err, lnum; | 1486 | int err, lnum; |
1477 | 1487 | ||
1478 | if (c->ro_media) | ||
1479 | return -EINVAL; | ||
1480 | |||
1481 | mutex_lock(&c->umount_mutex); | 1488 | mutex_lock(&c->umount_mutex); |
1489 | dbg_save_space_info(c); | ||
1482 | c->remounting_rw = 1; | 1490 | c->remounting_rw = 1; |
1483 | c->always_chk_crc = 1; | 1491 | c->always_chk_crc = 1; |
1484 | 1492 | ||
@@ -1514,6 +1522,12 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1514 | err = ubifs_recover_inl_heads(c, c->sbuf); | 1522 | err = ubifs_recover_inl_heads(c, c->sbuf); |
1515 | if (err) | 1523 | if (err) |
1516 | goto out; | 1524 | goto out; |
1525 | } else { | ||
1526 | /* A readonly mount is not allowed to have orphans */ | ||
1527 | ubifs_assert(c->tot_orphans == 0); | ||
1528 | err = ubifs_clear_orphans(c); | ||
1529 | if (err) | ||
1530 | goto out; | ||
1517 | } | 1531 | } |
1518 | 1532 | ||
1519 | if (!(c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY))) { | 1533 | if (!(c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY))) { |
@@ -1569,7 +1583,7 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1569 | if (c->need_recovery) | 1583 | if (c->need_recovery) |
1570 | err = ubifs_rcvry_gc_commit(c); | 1584 | err = ubifs_rcvry_gc_commit(c); |
1571 | else | 1585 | else |
1572 | err = take_gc_lnum(c); | 1586 | err = ubifs_leb_unmap(c, c->gc_lnum); |
1573 | if (err) | 1587 | if (err) |
1574 | goto out; | 1588 | goto out; |
1575 | 1589 | ||
@@ -1582,8 +1596,9 @@ static int ubifs_remount_rw(struct ubifs_info *c) | |||
1582 | c->vfs_sb->s_flags &= ~MS_RDONLY; | 1596 | c->vfs_sb->s_flags &= ~MS_RDONLY; |
1583 | c->remounting_rw = 0; | 1597 | c->remounting_rw = 0; |
1584 | c->always_chk_crc = 0; | 1598 | c->always_chk_crc = 0; |
1599 | err = dbg_check_space_info(c); | ||
1585 | mutex_unlock(&c->umount_mutex); | 1600 | mutex_unlock(&c->umount_mutex); |
1586 | return 0; | 1601 | return err; |
1587 | 1602 | ||
1588 | out: | 1603 | out: |
1589 | vfree(c->orph_buf); | 1604 | vfree(c->orph_buf); |
@@ -1603,43 +1618,18 @@ out: | |||
1603 | } | 1618 | } |
1604 | 1619 | ||
1605 | /** | 1620 | /** |
1606 | * commit_on_unmount - commit the journal when un-mounting. | ||
1607 | * @c: UBIFS file-system description object | ||
1608 | * | ||
1609 | * This function is called during un-mounting and re-mounting, and it commits | ||
1610 | * the journal unless the "fast unmount" mode is enabled. | ||
1611 | */ | ||
1612 | static void commit_on_unmount(struct ubifs_info *c) | ||
1613 | { | ||
1614 | struct super_block *sb = c->vfs_sb; | ||
1615 | long long bud_bytes; | ||
1616 | |||
1617 | /* | ||
1618 | * This function is called before the background thread is stopped, so | ||
1619 | * we may race with ongoing commit, which means we have to take | ||
1620 | * @c->bud_lock to access @c->bud_bytes. | ||
1621 | */ | ||
1622 | spin_lock(&c->buds_lock); | ||
1623 | bud_bytes = c->bud_bytes; | ||
1624 | spin_unlock(&c->buds_lock); | ||
1625 | |||
1626 | if (!c->fast_unmount && !(sb->s_flags & MS_RDONLY) && bud_bytes) | ||
1627 | ubifs_run_commit(c); | ||
1628 | } | ||
1629 | |||
1630 | /** | ||
1631 | * ubifs_remount_ro - re-mount in read-only mode. | 1621 | * ubifs_remount_ro - re-mount in read-only mode. |
1632 | * @c: UBIFS file-system description object | 1622 | * @c: UBIFS file-system description object |
1633 | * | 1623 | * |
1634 | * We rely on VFS to have stopped writing. Possibly the background thread could | 1624 | * We assume VFS has stopped writing. Possibly the background thread could be |
1635 | * be running a commit, however kthread_stop will wait in that case. | 1625 | * running a commit, however kthread_stop will wait in that case. |
1636 | */ | 1626 | */ |
1637 | static void ubifs_remount_ro(struct ubifs_info *c) | 1627 | static void ubifs_remount_ro(struct ubifs_info *c) |
1638 | { | 1628 | { |
1639 | int i, err; | 1629 | int i, err; |
1640 | 1630 | ||
1641 | ubifs_assert(!c->need_recovery); | 1631 | ubifs_assert(!c->need_recovery); |
1642 | commit_on_unmount(c); | 1632 | ubifs_assert(!(c->vfs_sb->s_flags & MS_RDONLY)); |
1643 | 1633 | ||
1644 | mutex_lock(&c->umount_mutex); | 1634 | mutex_lock(&c->umount_mutex); |
1645 | if (c->bgt) { | 1635 | if (c->bgt) { |
@@ -1647,27 +1637,29 @@ static void ubifs_remount_ro(struct ubifs_info *c) | |||
1647 | c->bgt = NULL; | 1637 | c->bgt = NULL; |
1648 | } | 1638 | } |
1649 | 1639 | ||
1640 | dbg_save_space_info(c); | ||
1641 | |||
1650 | for (i = 0; i < c->jhead_cnt; i++) { | 1642 | for (i = 0; i < c->jhead_cnt; i++) { |
1651 | ubifs_wbuf_sync(&c->jheads[i].wbuf); | 1643 | ubifs_wbuf_sync(&c->jheads[i].wbuf); |
1652 | del_timer_sync(&c->jheads[i].wbuf.timer); | 1644 | del_timer_sync(&c->jheads[i].wbuf.timer); |
1653 | } | 1645 | } |
1654 | 1646 | ||
1655 | if (!c->ro_media) { | 1647 | c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); |
1656 | c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); | 1648 | c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); |
1657 | c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); | 1649 | c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum); |
1658 | c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum); | 1650 | err = ubifs_write_master(c); |
1659 | err = ubifs_write_master(c); | 1651 | if (err) |
1660 | if (err) | 1652 | ubifs_ro_mode(c, err); |
1661 | ubifs_ro_mode(c, err); | ||
1662 | } | ||
1663 | 1653 | ||
1664 | ubifs_destroy_idx_gc(c); | ||
1665 | free_wbufs(c); | 1654 | free_wbufs(c); |
1666 | vfree(c->orph_buf); | 1655 | vfree(c->orph_buf); |
1667 | c->orph_buf = NULL; | 1656 | c->orph_buf = NULL; |
1668 | vfree(c->ileb_buf); | 1657 | vfree(c->ileb_buf); |
1669 | c->ileb_buf = NULL; | 1658 | c->ileb_buf = NULL; |
1670 | ubifs_lpt_free(c, 1); | 1659 | ubifs_lpt_free(c, 1); |
1660 | err = dbg_check_space_info(c); | ||
1661 | if (err) | ||
1662 | ubifs_ro_mode(c, err); | ||
1671 | mutex_unlock(&c->umount_mutex); | 1663 | mutex_unlock(&c->umount_mutex); |
1672 | } | 1664 | } |
1673 | 1665 | ||
@@ -1760,11 +1752,20 @@ static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data) | |||
1760 | } | 1752 | } |
1761 | 1753 | ||
1762 | if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { | 1754 | if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { |
1755 | if (c->ro_media) { | ||
1756 | ubifs_msg("cannot re-mount due to prior errors"); | ||
1757 | return -EROFS; | ||
1758 | } | ||
1763 | err = ubifs_remount_rw(c); | 1759 | err = ubifs_remount_rw(c); |
1764 | if (err) | 1760 | if (err) |
1765 | return err; | 1761 | return err; |
1766 | } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) | 1762 | } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) { |
1763 | if (c->ro_media) { | ||
1764 | ubifs_msg("cannot re-mount due to prior errors"); | ||
1765 | return -EROFS; | ||
1766 | } | ||
1767 | ubifs_remount_ro(c); | 1767 | ubifs_remount_ro(c); |
1768 | } | ||
1768 | 1769 | ||
1769 | if (c->bulk_read == 1) | 1770 | if (c->bulk_read == 1) |
1770 | bu_init(c); | 1771 | bu_init(c); |
@@ -1774,10 +1775,11 @@ static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data) | |||
1774 | c->bu.buf = NULL; | 1775 | c->bu.buf = NULL; |
1775 | } | 1776 | } |
1776 | 1777 | ||
1778 | ubifs_assert(c->lst.taken_empty_lebs == 1); | ||
1777 | return 0; | 1779 | return 0; |
1778 | } | 1780 | } |
1779 | 1781 | ||
1780 | struct super_operations ubifs_super_operations = { | 1782 | const struct super_operations ubifs_super_operations = { |
1781 | .alloc_inode = ubifs_alloc_inode, | 1783 | .alloc_inode = ubifs_alloc_inode, |
1782 | .destroy_inode = ubifs_destroy_inode, | 1784 | .destroy_inode = ubifs_destroy_inode, |
1783 | .put_super = ubifs_put_super, | 1785 | .put_super = ubifs_put_super, |
@@ -2044,15 +2046,6 @@ out_close: | |||
2044 | 2046 | ||
2045 | static void ubifs_kill_sb(struct super_block *sb) | 2047 | static void ubifs_kill_sb(struct super_block *sb) |
2046 | { | 2048 | { |
2047 | struct ubifs_info *c = sb->s_fs_info; | ||
2048 | |||
2049 | /* | ||
2050 | * We do 'commit_on_unmount()' here instead of 'ubifs_put_super()' | ||
2051 | * in order to be outside BKL. | ||
2052 | */ | ||
2053 | if (sb->s_root) | ||
2054 | commit_on_unmount(c); | ||
2055 | /* The un-mount routine is actually done in put_super() */ | ||
2056 | generic_shutdown_super(sb); | 2049 | generic_shutdown_super(sb); |
2057 | } | 2050 | } |
2058 | 2051 | ||
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c index f7e36f545527..fa28a84c6a1b 100644 --- a/fs/ubifs/tnc.c +++ b/fs/ubifs/tnc.c | |||
@@ -443,6 +443,11 @@ static int tnc_read_node_nm(struct ubifs_info *c, struct ubifs_zbranch *zbr, | |||
443 | * This function performs that same function as ubifs_read_node except that | 443 | * This function performs that same function as ubifs_read_node except that |
444 | * it does not require that there is actually a node present and instead | 444 | * it does not require that there is actually a node present and instead |
445 | * the return code indicates if a node was read. | 445 | * the return code indicates if a node was read. |
446 | * | ||
447 | * Note, this function does not check CRC of data nodes if @c->no_chk_data_crc | ||
448 | * is true (it is controlled by corresponding mount option). However, if | ||
449 | * @c->always_chk_crc is true, @c->no_chk_data_crc is ignored and CRC is always | ||
450 | * checked. | ||
446 | */ | 451 | */ |
447 | static int try_read_node(const struct ubifs_info *c, void *buf, int type, | 452 | static int try_read_node(const struct ubifs_info *c, void *buf, int type, |
448 | int len, int lnum, int offs) | 453 | int len, int lnum, int offs) |
@@ -470,9 +475,8 @@ static int try_read_node(const struct ubifs_info *c, void *buf, int type, | |||
470 | if (node_len != len) | 475 | if (node_len != len) |
471 | return 0; | 476 | return 0; |
472 | 477 | ||
473 | if (type == UBIFS_DATA_NODE && !c->always_chk_crc) | 478 | if (type == UBIFS_DATA_NODE && !c->always_chk_crc && c->no_chk_data_crc) |
474 | if (c->no_chk_data_crc) | 479 | return 1; |
475 | return 0; | ||
476 | 480 | ||
477 | crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); | 481 | crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); |
478 | node_crc = le32_to_cpu(ch->crc); | 482 | node_crc = le32_to_cpu(ch->crc); |
@@ -1506,7 +1510,7 @@ out: | |||
1506 | * | 1510 | * |
1507 | * Note, if the bulk-read buffer length (@bu->buf_len) is known, this function | 1511 | * Note, if the bulk-read buffer length (@bu->buf_len) is known, this function |
1508 | * makes sure bulk-read nodes fit the buffer. Otherwise, this function prepares | 1512 | * makes sure bulk-read nodes fit the buffer. Otherwise, this function prepares |
1509 | * maxumum possible amount of nodes for bulk-read. | 1513 | * maximum possible amount of nodes for bulk-read. |
1510 | */ | 1514 | */ |
1511 | int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu) | 1515 | int ubifs_tnc_get_bu_keys(struct ubifs_info *c, struct bu_info *bu) |
1512 | { | 1516 | { |
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index fc2a4cc66d03..039a68bee29a 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h | |||
@@ -426,9 +426,9 @@ struct ubifs_unclean_leb { | |||
426 | * LEB properties flags. | 426 | * LEB properties flags. |
427 | * | 427 | * |
428 | * LPROPS_UNCAT: not categorized | 428 | * LPROPS_UNCAT: not categorized |
429 | * LPROPS_DIRTY: dirty > 0, not index | 429 | * LPROPS_DIRTY: dirty > free, dirty >= @c->dead_wm, not index |
430 | * LPROPS_DIRTY_IDX: dirty + free > @c->min_idx_node_sze and index | 430 | * LPROPS_DIRTY_IDX: dirty + free > @c->min_idx_node_sze and index |
431 | * LPROPS_FREE: free > 0, not empty, not index | 431 | * LPROPS_FREE: free > 0, dirty < @c->dead_wm, not empty, not index |
432 | * LPROPS_HEAP_CNT: number of heaps used for storing categorized LEBs | 432 | * LPROPS_HEAP_CNT: number of heaps used for storing categorized LEBs |
433 | * LPROPS_EMPTY: LEB is empty, not taken | 433 | * LPROPS_EMPTY: LEB is empty, not taken |
434 | * LPROPS_FREEABLE: free + dirty == leb_size, not index, not taken | 434 | * LPROPS_FREEABLE: free + dirty == leb_size, not index, not taken |
@@ -961,7 +961,6 @@ struct ubifs_debug_info; | |||
961 | * @cs_lock: commit state lock | 961 | * @cs_lock: commit state lock |
962 | * @cmt_wq: wait queue to sleep on if the log is full and a commit is running | 962 | * @cmt_wq: wait queue to sleep on if the log is full and a commit is running |
963 | * | 963 | * |
964 | * @fast_unmount: do not run journal commit before un-mounting | ||
965 | * @big_lpt: flag that LPT is too big to write whole during commit | 964 | * @big_lpt: flag that LPT is too big to write whole during commit |
966 | * @no_chk_data_crc: do not check CRCs when reading data nodes (except during | 965 | * @no_chk_data_crc: do not check CRCs when reading data nodes (except during |
967 | * recovery) | 966 | * recovery) |
@@ -1202,7 +1201,6 @@ struct ubifs_info { | |||
1202 | spinlock_t cs_lock; | 1201 | spinlock_t cs_lock; |
1203 | wait_queue_head_t cmt_wq; | 1202 | wait_queue_head_t cmt_wq; |
1204 | 1203 | ||
1205 | unsigned int fast_unmount:1; | ||
1206 | unsigned int big_lpt:1; | 1204 | unsigned int big_lpt:1; |
1207 | unsigned int no_chk_data_crc:1; | 1205 | unsigned int no_chk_data_crc:1; |
1208 | unsigned int bulk_read:1; | 1206 | unsigned int bulk_read:1; |
@@ -1405,13 +1403,13 @@ extern struct list_head ubifs_infos; | |||
1405 | extern spinlock_t ubifs_infos_lock; | 1403 | extern spinlock_t ubifs_infos_lock; |
1406 | extern atomic_long_t ubifs_clean_zn_cnt; | 1404 | extern atomic_long_t ubifs_clean_zn_cnt; |
1407 | extern struct kmem_cache *ubifs_inode_slab; | 1405 | extern struct kmem_cache *ubifs_inode_slab; |
1408 | extern struct super_operations ubifs_super_operations; | 1406 | extern const struct super_operations ubifs_super_operations; |
1409 | extern struct address_space_operations ubifs_file_address_operations; | 1407 | extern const struct address_space_operations ubifs_file_address_operations; |
1410 | extern struct file_operations ubifs_file_operations; | 1408 | extern const struct file_operations ubifs_file_operations; |
1411 | extern struct inode_operations ubifs_file_inode_operations; | 1409 | extern const struct inode_operations ubifs_file_inode_operations; |
1412 | extern struct file_operations ubifs_dir_operations; | 1410 | extern const struct file_operations ubifs_dir_operations; |
1413 | extern struct inode_operations ubifs_dir_inode_operations; | 1411 | extern const struct inode_operations ubifs_dir_inode_operations; |
1414 | extern struct inode_operations ubifs_symlink_inode_operations; | 1412 | extern const struct inode_operations ubifs_symlink_inode_operations; |
1415 | extern struct backing_dev_info ubifs_backing_dev_info; | 1413 | extern struct backing_dev_info ubifs_backing_dev_info; |
1416 | extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; | 1414 | extern struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; |
1417 | 1415 | ||
@@ -1428,7 +1426,7 @@ int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, | |||
1428 | int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, | 1426 | int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum, |
1429 | int offs, int dtype); | 1427 | int offs, int dtype); |
1430 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, | 1428 | int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, |
1431 | int offs, int quiet, int chk_crc); | 1429 | int offs, int quiet, int must_chk_crc); |
1432 | void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); | 1430 | void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); |
1433 | void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last); | 1431 | void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last); |
1434 | int ubifs_io_init(struct ubifs_info *c); | 1432 | int ubifs_io_init(struct ubifs_info *c); |
@@ -1495,6 +1493,7 @@ void ubifs_release_ino_dirty(struct ubifs_info *c, struct inode *inode, | |||
1495 | void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode, | 1493 | void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode, |
1496 | struct ubifs_budget_req *req); | 1494 | struct ubifs_budget_req *req); |
1497 | long long ubifs_get_free_space(struct ubifs_info *c); | 1495 | long long ubifs_get_free_space(struct ubifs_info *c); |
1496 | long long ubifs_get_free_space_nolock(struct ubifs_info *c); | ||
1498 | int ubifs_calc_min_idx_lebs(struct ubifs_info *c); | 1497 | int ubifs_calc_min_idx_lebs(struct ubifs_info *c); |
1499 | void ubifs_convert_page_budget(struct ubifs_info *c); | 1498 | void ubifs_convert_page_budget(struct ubifs_info *c); |
1500 | long long ubifs_reported_space(const struct ubifs_info *c, long long free); | 1499 | long long ubifs_reported_space(const struct ubifs_info *c, long long free); |
@@ -1603,6 +1602,7 @@ void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum); | |||
1603 | int ubifs_orphan_start_commit(struct ubifs_info *c); | 1602 | int ubifs_orphan_start_commit(struct ubifs_info *c); |
1604 | int ubifs_orphan_end_commit(struct ubifs_info *c); | 1603 | int ubifs_orphan_end_commit(struct ubifs_info *c); |
1605 | int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only); | 1604 | int ubifs_mount_orphans(struct ubifs_info *c, int unclean, int read_only); |
1605 | int ubifs_clear_orphans(struct ubifs_info *c); | ||
1606 | 1606 | ||
1607 | /* lpt.c */ | 1607 | /* lpt.c */ |
1608 | int ubifs_calc_lpt_geom(struct ubifs_info *c); | 1608 | int ubifs_calc_lpt_geom(struct ubifs_info *c); |
@@ -1646,7 +1646,7 @@ const struct ubifs_lprops *ubifs_change_lp(struct ubifs_info *c, | |||
1646 | const struct ubifs_lprops *lp, | 1646 | const struct ubifs_lprops *lp, |
1647 | int free, int dirty, int flags, | 1647 | int free, int dirty, int flags, |
1648 | int idx_gc_cnt); | 1648 | int idx_gc_cnt); |
1649 | void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *stats); | 1649 | void ubifs_get_lp_stats(struct ubifs_info *c, struct ubifs_lp_stats *lst); |
1650 | void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops, | 1650 | void ubifs_add_to_cat(struct ubifs_info *c, struct ubifs_lprops *lprops, |
1651 | int cat); | 1651 | int cat); |
1652 | void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops, | 1652 | void ubifs_replace_cat(struct ubifs_info *c, struct ubifs_lprops *old_lprops, |
diff --git a/fs/xfs/linux-2.6/xfs_sync.c b/fs/xfs/linux-2.6/xfs_sync.c index 2ed035354c26..a608e72fa405 100644 --- a/fs/xfs/linux-2.6/xfs_sync.c +++ b/fs/xfs/linux-2.6/xfs_sync.c | |||
@@ -371,7 +371,11 @@ xfs_quiesce_attr( | |||
371 | /* flush inodes and push all remaining buffers out to disk */ | 371 | /* flush inodes and push all remaining buffers out to disk */ |
372 | xfs_quiesce_fs(mp); | 372 | xfs_quiesce_fs(mp); |
373 | 373 | ||
374 | ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0); | 374 | /* |
375 | * Just warn here till VFS can correctly support | ||
376 | * read-only remount without racing. | ||
377 | */ | ||
378 | WARN_ON(atomic_read(&mp->m_active_trans) != 0); | ||
375 | 379 | ||
376 | /* Push the superblock and write an unmount record */ | 380 | /* Push the superblock and write an unmount record */ |
377 | error = xfs_log_sbcount(mp, 1); | 381 | error = xfs_log_sbcount(mp, 1); |
diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c index b4c1ee713492..f8278cfcc1d3 100644 --- a/fs/xfs/xfs_dfrag.c +++ b/fs/xfs/xfs_dfrag.c | |||
@@ -55,17 +55,11 @@ xfs_swapext( | |||
55 | struct file *file, *target_file; | 55 | struct file *file, *target_file; |
56 | int error = 0; | 56 | int error = 0; |
57 | 57 | ||
58 | sxp = kmem_alloc(sizeof(xfs_swapext_t), KM_MAYFAIL); | ||
59 | if (!sxp) { | ||
60 | error = XFS_ERROR(ENOMEM); | ||
61 | goto out; | ||
62 | } | ||
63 | |||
64 | /* Pull information for the target fd */ | 58 | /* Pull information for the target fd */ |
65 | file = fget((int)sxp->sx_fdtarget); | 59 | file = fget((int)sxp->sx_fdtarget); |
66 | if (!file) { | 60 | if (!file) { |
67 | error = XFS_ERROR(EINVAL); | 61 | error = XFS_ERROR(EINVAL); |
68 | goto out_free_sxp; | 62 | goto out; |
69 | } | 63 | } |
70 | 64 | ||
71 | if (!(file->f_mode & FMODE_WRITE) || (file->f_flags & O_APPEND)) { | 65 | if (!(file->f_mode & FMODE_WRITE) || (file->f_flags & O_APPEND)) { |
@@ -109,8 +103,6 @@ xfs_swapext( | |||
109 | fput(target_file); | 103 | fput(target_file); |
110 | out_put_file: | 104 | out_put_file: |
111 | fput(file); | 105 | fput(file); |
112 | out_free_sxp: | ||
113 | kmem_free(sxp); | ||
114 | out: | 106 | out: |
115 | return error; | 107 | return error; |
116 | } | 108 | } |
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index 35cca98bd94c..b1047de2fffd 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c | |||
@@ -70,16 +70,21 @@ STATIC void xlog_recover_check_summary(xlog_t *); | |||
70 | xfs_buf_t * | 70 | xfs_buf_t * |
71 | xlog_get_bp( | 71 | xlog_get_bp( |
72 | xlog_t *log, | 72 | xlog_t *log, |
73 | int num_bblks) | 73 | int nbblks) |
74 | { | 74 | { |
75 | ASSERT(num_bblks > 0); | 75 | if (nbblks <= 0 || nbblks > log->l_logBBsize) { |
76 | xlog_warn("XFS: Invalid block length (0x%x) given for buffer", nbblks); | ||
77 | XFS_ERROR_REPORT("xlog_get_bp(1)", | ||
78 | XFS_ERRLEVEL_HIGH, log->l_mp); | ||
79 | return NULL; | ||
80 | } | ||
76 | 81 | ||
77 | if (log->l_sectbb_log) { | 82 | if (log->l_sectbb_log) { |
78 | if (num_bblks > 1) | 83 | if (nbblks > 1) |
79 | num_bblks += XLOG_SECTOR_ROUNDUP_BBCOUNT(log, 1); | 84 | nbblks += XLOG_SECTOR_ROUNDUP_BBCOUNT(log, 1); |
80 | num_bblks = XLOG_SECTOR_ROUNDUP_BBCOUNT(log, num_bblks); | 85 | nbblks = XLOG_SECTOR_ROUNDUP_BBCOUNT(log, nbblks); |
81 | } | 86 | } |
82 | return xfs_buf_get_noaddr(BBTOB(num_bblks), log->l_mp->m_logdev_targp); | 87 | return xfs_buf_get_noaddr(BBTOB(nbblks), log->l_mp->m_logdev_targp); |
83 | } | 88 | } |
84 | 89 | ||
85 | void | 90 | void |
@@ -102,6 +107,13 @@ xlog_bread( | |||
102 | { | 107 | { |
103 | int error; | 108 | int error; |
104 | 109 | ||
110 | if (nbblks <= 0 || nbblks > log->l_logBBsize) { | ||
111 | xlog_warn("XFS: Invalid block length (0x%x) given for buffer", nbblks); | ||
112 | XFS_ERROR_REPORT("xlog_bread(1)", | ||
113 | XFS_ERRLEVEL_HIGH, log->l_mp); | ||
114 | return EFSCORRUPTED; | ||
115 | } | ||
116 | |||
105 | if (log->l_sectbb_log) { | 117 | if (log->l_sectbb_log) { |
106 | blk_no = XLOG_SECTOR_ROUNDDOWN_BLKNO(log, blk_no); | 118 | blk_no = XLOG_SECTOR_ROUNDDOWN_BLKNO(log, blk_no); |
107 | nbblks = XLOG_SECTOR_ROUNDUP_BBCOUNT(log, nbblks); | 119 | nbblks = XLOG_SECTOR_ROUNDUP_BBCOUNT(log, nbblks); |
@@ -139,6 +151,13 @@ xlog_bwrite( | |||
139 | { | 151 | { |
140 | int error; | 152 | int error; |
141 | 153 | ||
154 | if (nbblks <= 0 || nbblks > log->l_logBBsize) { | ||
155 | xlog_warn("XFS: Invalid block length (0x%x) given for buffer", nbblks); | ||
156 | XFS_ERROR_REPORT("xlog_bwrite(1)", | ||
157 | XFS_ERRLEVEL_HIGH, log->l_mp); | ||
158 | return EFSCORRUPTED; | ||
159 | } | ||
160 | |||
142 | if (log->l_sectbb_log) { | 161 | if (log->l_sectbb_log) { |
143 | blk_no = XLOG_SECTOR_ROUNDDOWN_BLKNO(log, blk_no); | 162 | blk_no = XLOG_SECTOR_ROUNDDOWN_BLKNO(log, blk_no); |
144 | nbblks = XLOG_SECTOR_ROUNDUP_BBCOUNT(log, nbblks); | 163 | nbblks = XLOG_SECTOR_ROUNDUP_BBCOUNT(log, nbblks); |