diff options
Diffstat (limited to 'fs')
71 files changed, 2488 insertions, 2123 deletions
diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES index 49503d2edc7e..bc0025cdd1c9 100644 --- a/fs/cifs/CHANGES +++ b/fs/cifs/CHANGES | |||
@@ -1,6 +1,7 @@ | |||
1 | Version 1.62 | 1 | Version 1.62 |
2 | ------------ | 2 | ------------ |
3 | Add sockopt=TCP_NODELAY mount option. | 3 | Add sockopt=TCP_NODELAY mount option. EA (xattr) routines hardened |
4 | to more strictly handle corrupt frames. | ||
4 | 5 | ||
5 | Version 1.61 | 6 | Version 1.61 |
6 | ------------ | 7 | ------------ |
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index ed751bb657db..a1c817eb291a 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
@@ -205,7 +205,7 @@ struct cifsUidInfo { | |||
205 | struct cifsSesInfo { | 205 | struct cifsSesInfo { |
206 | struct list_head smb_ses_list; | 206 | struct list_head smb_ses_list; |
207 | struct list_head tcon_list; | 207 | struct list_head tcon_list; |
208 | struct semaphore sesSem; | 208 | struct mutex session_mutex; |
209 | #if 0 | 209 | #if 0 |
210 | struct cifsUidInfo *uidInfo; /* pointer to user info */ | 210 | struct cifsUidInfo *uidInfo; /* pointer to user info */ |
211 | #endif | 211 | #endif |
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h index 3877737f96a6..14d036d8db11 100644 --- a/fs/cifs/cifspdu.h +++ b/fs/cifs/cifspdu.h | |||
@@ -415,10 +415,10 @@ struct smb_hdr { | |||
415 | __u8 WordCount; | 415 | __u8 WordCount; |
416 | } __attribute__((packed)); | 416 | } __attribute__((packed)); |
417 | /* given a pointer to an smb_hdr retrieve the value of byte count */ | 417 | /* given a pointer to an smb_hdr retrieve the value of byte count */ |
418 | #define BCC(smb_var) (*(__u16 *)((char *)smb_var + sizeof(struct smb_hdr) + (2 * smb_var->WordCount))) | 418 | #define BCC(smb_var) (*(__u16 *)((char *)(smb_var) + sizeof(struct smb_hdr) + (2 * (smb_var)->WordCount))) |
419 | #define BCC_LE(smb_var) (*(__le16 *)((char *)smb_var + sizeof(struct smb_hdr) + (2 * smb_var->WordCount))) | 419 | #define BCC_LE(smb_var) (*(__le16 *)((char *)(smb_var) + sizeof(struct smb_hdr) + (2 * (smb_var)->WordCount))) |
420 | /* given a pointer to an smb_hdr retrieve the pointer to the byte area */ | 420 | /* given a pointer to an smb_hdr retrieve the pointer to the byte area */ |
421 | #define pByteArea(smb_var) ((unsigned char *)smb_var + sizeof(struct smb_hdr) + (2 * smb_var->WordCount) + 2) | 421 | #define pByteArea(smb_var) ((unsigned char *)(smb_var) + sizeof(struct smb_hdr) + (2 * (smb_var)->WordCount) + 2) |
422 | 422 | ||
423 | /* | 423 | /* |
424 | * Computer Name Length (since Netbios name was length 16 with last byte 0x20) | 424 | * Computer Name Length (since Netbios name was length 16 with last byte 0x20) |
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 5646727e33f5..88e2bc44ac58 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h | |||
@@ -363,13 +363,10 @@ extern int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, | |||
363 | __u32 filter, struct file *file, int multishot, | 363 | __u32 filter, struct file *file, int multishot, |
364 | const struct nls_table *nls_codepage); | 364 | const struct nls_table *nls_codepage); |
365 | extern ssize_t CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, | 365 | extern ssize_t CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, |
366 | const unsigned char *searchName, char *EAData, | 366 | const unsigned char *searchName, |
367 | const unsigned char *ea_name, char *EAData, | ||
367 | size_t bufsize, const struct nls_table *nls_codepage, | 368 | size_t bufsize, const struct nls_table *nls_codepage, |
368 | int remap_special_chars); | 369 | int remap_special_chars); |
369 | extern ssize_t CIFSSMBQueryEA(const int xid, struct cifsTconInfo *tcon, | ||
370 | const unsigned char *searchName, const unsigned char *ea_name, | ||
371 | unsigned char *ea_value, size_t buf_size, | ||
372 | const struct nls_table *nls_codepage, int remap_special_chars); | ||
373 | extern int CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, | 370 | extern int CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, |
374 | const char *fileName, const char *ea_name, | 371 | const char *fileName, const char *ea_name, |
375 | const void *ea_value, const __u16 ea_value_len, | 372 | const void *ea_value, const __u16 ea_value_len, |
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 941441d3e386..9d17df3e0768 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
@@ -170,19 +170,19 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command) | |||
170 | * need to prevent multiple threads trying to simultaneously | 170 | * need to prevent multiple threads trying to simultaneously |
171 | * reconnect the same SMB session | 171 | * reconnect the same SMB session |
172 | */ | 172 | */ |
173 | down(&ses->sesSem); | 173 | mutex_lock(&ses->session_mutex); |
174 | if (ses->need_reconnect) | 174 | if (ses->need_reconnect) |
175 | rc = cifs_setup_session(0, ses, nls_codepage); | 175 | rc = cifs_setup_session(0, ses, nls_codepage); |
176 | 176 | ||
177 | /* do we need to reconnect tcon? */ | 177 | /* do we need to reconnect tcon? */ |
178 | if (rc || !tcon->need_reconnect) { | 178 | if (rc || !tcon->need_reconnect) { |
179 | up(&ses->sesSem); | 179 | mutex_unlock(&ses->session_mutex); |
180 | goto out; | 180 | goto out; |
181 | } | 181 | } |
182 | 182 | ||
183 | mark_open_files_invalid(tcon); | 183 | mark_open_files_invalid(tcon); |
184 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); | 184 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); |
185 | up(&ses->sesSem); | 185 | mutex_unlock(&ses->session_mutex); |
186 | cFYI(1, ("reconnect tcon rc = %d", rc)); | 186 | cFYI(1, ("reconnect tcon rc = %d", rc)); |
187 | 187 | ||
188 | if (rc) | 188 | if (rc) |
@@ -700,13 +700,13 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) | |||
700 | if (!ses || !ses->server) | 700 | if (!ses || !ses->server) |
701 | return -EIO; | 701 | return -EIO; |
702 | 702 | ||
703 | down(&ses->sesSem); | 703 | mutex_lock(&ses->session_mutex); |
704 | if (ses->need_reconnect) | 704 | if (ses->need_reconnect) |
705 | goto session_already_dead; /* no need to send SMBlogoff if uid | 705 | goto session_already_dead; /* no need to send SMBlogoff if uid |
706 | already closed due to reconnect */ | 706 | already closed due to reconnect */ |
707 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); | 707 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
708 | if (rc) { | 708 | if (rc) { |
709 | up(&ses->sesSem); | 709 | mutex_unlock(&ses->session_mutex); |
710 | return rc; | 710 | return rc; |
711 | } | 711 | } |
712 | 712 | ||
@@ -721,7 +721,7 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) | |||
721 | pSMB->AndXCommand = 0xFF; | 721 | pSMB->AndXCommand = 0xFF; |
722 | rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); | 722 | rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); |
723 | session_already_dead: | 723 | session_already_dead: |
724 | up(&ses->sesSem); | 724 | mutex_unlock(&ses->session_mutex); |
725 | 725 | ||
726 | /* if session dead then we do not need to do ulogoff, | 726 | /* if session dead then we do not need to do ulogoff, |
727 | since server closed smb session, no sense reporting | 727 | since server closed smb session, no sense reporting |
@@ -5269,22 +5269,34 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, | |||
5269 | cifs_buf_release(pSMB); | 5269 | cifs_buf_release(pSMB); |
5270 | return rc; | 5270 | return rc; |
5271 | } | 5271 | } |
5272 | |||
5272 | #ifdef CONFIG_CIFS_XATTR | 5273 | #ifdef CONFIG_CIFS_XATTR |
5274 | /* | ||
5275 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common | ||
5276 | * function used by listxattr and getxattr type calls. When ea_name is set, | ||
5277 | * it looks for that attribute name and stuffs that value into the EAData | ||
5278 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the | ||
5279 | * buffer. In both cases, the return value is either the length of the | ||
5280 | * resulting data or a negative error code. If EAData is a NULL pointer then | ||
5281 | * the data isn't copied to it, but the length is returned. | ||
5282 | */ | ||
5273 | ssize_t | 5283 | ssize_t |
5274 | CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, | 5284 | CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, |
5275 | const unsigned char *searchName, | 5285 | const unsigned char *searchName, const unsigned char *ea_name, |
5276 | char *EAData, size_t buf_size, | 5286 | char *EAData, size_t buf_size, |
5277 | const struct nls_table *nls_codepage, int remap) | 5287 | const struct nls_table *nls_codepage, int remap) |
5278 | { | 5288 | { |
5279 | /* BB assumes one setup word */ | 5289 | /* BB assumes one setup word */ |
5280 | TRANSACTION2_QPI_REQ *pSMB = NULL; | 5290 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
5281 | TRANSACTION2_QPI_RSP *pSMBr = NULL; | 5291 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
5282 | int rc = 0; | 5292 | int rc = 0; |
5283 | int bytes_returned; | 5293 | int bytes_returned; |
5284 | int name_len; | 5294 | int list_len; |
5295 | struct fealist *ea_response_data; | ||
5285 | struct fea *temp_fea; | 5296 | struct fea *temp_fea; |
5286 | char *temp_ptr; | 5297 | char *temp_ptr; |
5287 | __u16 params, byte_count; | 5298 | char *end_of_smb; |
5299 | __u16 params, byte_count, data_offset; | ||
5288 | 5300 | ||
5289 | cFYI(1, ("In Query All EAs path %s", searchName)); | 5301 | cFYI(1, ("In Query All EAs path %s", searchName)); |
5290 | QAllEAsRetry: | 5302 | QAllEAsRetry: |
@@ -5294,22 +5306,22 @@ QAllEAsRetry: | |||
5294 | return rc; | 5306 | return rc; |
5295 | 5307 | ||
5296 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 5308 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
5297 | name_len = | 5309 | list_len = |
5298 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, | 5310 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
5299 | PATH_MAX, nls_codepage, remap); | 5311 | PATH_MAX, nls_codepage, remap); |
5300 | name_len++; /* trailing null */ | 5312 | list_len++; /* trailing null */ |
5301 | name_len *= 2; | 5313 | list_len *= 2; |
5302 | } else { /* BB improve the check for buffer overruns BB */ | 5314 | } else { /* BB improve the check for buffer overruns BB */ |
5303 | name_len = strnlen(searchName, PATH_MAX); | 5315 | list_len = strnlen(searchName, PATH_MAX); |
5304 | name_len++; /* trailing null */ | 5316 | list_len++; /* trailing null */ |
5305 | strncpy(pSMB->FileName, searchName, name_len); | 5317 | strncpy(pSMB->FileName, searchName, list_len); |
5306 | } | 5318 | } |
5307 | 5319 | ||
5308 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; | 5320 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
5309 | pSMB->TotalDataCount = 0; | 5321 | pSMB->TotalDataCount = 0; |
5310 | pSMB->MaxParameterCount = cpu_to_le16(2); | 5322 | pSMB->MaxParameterCount = cpu_to_le16(2); |
5311 | /* BB find exact max SMB PDU from sess structure BB */ | 5323 | /* BB find exact max SMB PDU from sess structure BB */ |
5312 | pSMB->MaxDataCount = cpu_to_le16(4000); | 5324 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
5313 | pSMB->MaxSetupCount = 0; | 5325 | pSMB->MaxSetupCount = 0; |
5314 | pSMB->Reserved = 0; | 5326 | pSMB->Reserved = 0; |
5315 | pSMB->Flags = 0; | 5327 | pSMB->Flags = 0; |
@@ -5334,237 +5346,117 @@ QAllEAsRetry: | |||
5334 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 5346 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
5335 | if (rc) { | 5347 | if (rc) { |
5336 | cFYI(1, ("Send error in QueryAllEAs = %d", rc)); | 5348 | cFYI(1, ("Send error in QueryAllEAs = %d", rc)); |
5337 | } else { /* decode response */ | 5349 | goto QAllEAsOut; |
5338 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 5350 | } |
5339 | 5351 | ||
5340 | /* BB also check enough total bytes returned */ | 5352 | |
5341 | /* BB we need to improve the validity checking | 5353 | /* BB also check enough total bytes returned */ |
5342 | of these trans2 responses */ | 5354 | /* BB we need to improve the validity checking |
5343 | if (rc || (pSMBr->ByteCount < 4)) | 5355 | of these trans2 responses */ |
5344 | rc = -EIO; /* bad smb */ | 5356 | |
5345 | /* else if (pFindData){ | 5357 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
5346 | memcpy((char *) pFindData, | 5358 | if (rc || (pSMBr->ByteCount < 4)) { |
5347 | (char *) &pSMBr->hdr.Protocol + | 5359 | rc = -EIO; /* bad smb */ |
5348 | data_offset, kl); | 5360 | goto QAllEAsOut; |
5349 | }*/ else { | ||
5350 | /* check that length of list is not more than bcc */ | ||
5351 | /* check that each entry does not go beyond length | ||
5352 | of list */ | ||
5353 | /* check that each element of each entry does not | ||
5354 | go beyond end of list */ | ||
5355 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | ||
5356 | struct fealist *ea_response_data; | ||
5357 | rc = 0; | ||
5358 | /* validate_trans2_offsets() */ | ||
5359 | /* BB check if start of smb + data_offset > &bcc+ bcc */ | ||
5360 | ea_response_data = (struct fealist *) | ||
5361 | (((char *) &pSMBr->hdr.Protocol) + | ||
5362 | data_offset); | ||
5363 | name_len = le32_to_cpu(ea_response_data->list_len); | ||
5364 | cFYI(1, ("ea length %d", name_len)); | ||
5365 | if (name_len <= 8) { | ||
5366 | /* returned EA size zeroed at top of function */ | ||
5367 | cFYI(1, ("empty EA list returned from server")); | ||
5368 | } else { | ||
5369 | /* account for ea list len */ | ||
5370 | name_len -= 4; | ||
5371 | temp_fea = ea_response_data->list; | ||
5372 | temp_ptr = (char *)temp_fea; | ||
5373 | while (name_len > 0) { | ||
5374 | __u16 value_len; | ||
5375 | name_len -= 4; | ||
5376 | temp_ptr += 4; | ||
5377 | rc += temp_fea->name_len; | ||
5378 | /* account for prefix user. and trailing null */ | ||
5379 | rc = rc + 5 + 1; | ||
5380 | if (rc < (int)buf_size) { | ||
5381 | memcpy(EAData, "user.", 5); | ||
5382 | EAData += 5; | ||
5383 | memcpy(EAData, temp_ptr, | ||
5384 | temp_fea->name_len); | ||
5385 | EAData += temp_fea->name_len; | ||
5386 | /* null terminate name */ | ||
5387 | *EAData = 0; | ||
5388 | EAData = EAData + 1; | ||
5389 | } else if (buf_size == 0) { | ||
5390 | /* skip copy - calc size only */ | ||
5391 | } else { | ||
5392 | /* stop before overrun buffer */ | ||
5393 | rc = -ERANGE; | ||
5394 | break; | ||
5395 | } | ||
5396 | name_len -= temp_fea->name_len; | ||
5397 | temp_ptr += temp_fea->name_len; | ||
5398 | /* account for trailing null */ | ||
5399 | name_len--; | ||
5400 | temp_ptr++; | ||
5401 | value_len = | ||
5402 | le16_to_cpu(temp_fea->value_len); | ||
5403 | name_len -= value_len; | ||
5404 | temp_ptr += value_len; | ||
5405 | /* BB check that temp_ptr is still | ||
5406 | within the SMB BB*/ | ||
5407 | |||
5408 | /* no trailing null to account for | ||
5409 | in value len */ | ||
5410 | /* go on to next EA */ | ||
5411 | temp_fea = (struct fea *)temp_ptr; | ||
5412 | } | ||
5413 | } | ||
5414 | } | ||
5415 | } | 5361 | } |
5416 | cifs_buf_release(pSMB); | ||
5417 | if (rc == -EAGAIN) | ||
5418 | goto QAllEAsRetry; | ||
5419 | 5362 | ||
5420 | return (ssize_t)rc; | 5363 | /* check that length of list is not more than bcc */ |
5421 | } | 5364 | /* check that each entry does not go beyond length |
5365 | of list */ | ||
5366 | /* check that each element of each entry does not | ||
5367 | go beyond end of list */ | ||
5368 | /* validate_trans2_offsets() */ | ||
5369 | /* BB check if start of smb + data_offset > &bcc+ bcc */ | ||
5422 | 5370 | ||
5423 | ssize_t CIFSSMBQueryEA(const int xid, struct cifsTconInfo *tcon, | 5371 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
5424 | const unsigned char *searchName, const unsigned char *ea_name, | 5372 | ea_response_data = (struct fealist *) |
5425 | unsigned char *ea_value, size_t buf_size, | 5373 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
5426 | const struct nls_table *nls_codepage, int remap) | ||
5427 | { | ||
5428 | TRANSACTION2_QPI_REQ *pSMB = NULL; | ||
5429 | TRANSACTION2_QPI_RSP *pSMBr = NULL; | ||
5430 | int rc = 0; | ||
5431 | int bytes_returned; | ||
5432 | int name_len; | ||
5433 | struct fea *temp_fea; | ||
5434 | char *temp_ptr; | ||
5435 | __u16 params, byte_count; | ||
5436 | 5374 | ||
5437 | cFYI(1, ("In Query EA path %s", searchName)); | 5375 | list_len = le32_to_cpu(ea_response_data->list_len); |
5438 | QEARetry: | 5376 | cFYI(1, ("ea length %d", list_len)); |
5439 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 5377 | if (list_len <= 8) { |
5440 | (void **) &pSMBr); | 5378 | cFYI(1, ("empty EA list returned from server")); |
5441 | if (rc) | 5379 | goto QAllEAsOut; |
5442 | return rc; | 5380 | } |
5443 | 5381 | ||
5444 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 5382 | /* make sure list_len doesn't go past end of SMB */ |
5445 | name_len = | 5383 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + BCC(&pSMBr->hdr); |
5446 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, | 5384 | if ((char *)ea_response_data + list_len > end_of_smb) { |
5447 | PATH_MAX, nls_codepage, remap); | 5385 | cFYI(1, ("EA list appears to go beyond SMB")); |
5448 | name_len++; /* trailing null */ | 5386 | rc = -EIO; |
5449 | name_len *= 2; | 5387 | goto QAllEAsOut; |
5450 | } else { /* BB improve the check for buffer overruns BB */ | ||
5451 | name_len = strnlen(searchName, PATH_MAX); | ||
5452 | name_len++; /* trailing null */ | ||
5453 | strncpy(pSMB->FileName, searchName, name_len); | ||
5454 | } | 5388 | } |
5455 | 5389 | ||
5456 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; | 5390 | /* account for ea list len */ |
5457 | pSMB->TotalDataCount = 0; | 5391 | list_len -= 4; |
5458 | pSMB->MaxParameterCount = cpu_to_le16(2); | 5392 | temp_fea = ea_response_data->list; |
5459 | /* BB find exact max SMB PDU from sess structure BB */ | 5393 | temp_ptr = (char *)temp_fea; |
5460 | pSMB->MaxDataCount = cpu_to_le16(4000); | 5394 | while (list_len > 0) { |
5461 | pSMB->MaxSetupCount = 0; | 5395 | unsigned int name_len; |
5462 | pSMB->Reserved = 0; | 5396 | __u16 value_len; |
5463 | pSMB->Flags = 0; | 5397 | |
5464 | pSMB->Timeout = 0; | 5398 | list_len -= 4; |
5465 | pSMB->Reserved2 = 0; | 5399 | temp_ptr += 4; |
5466 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 5400 | /* make sure we can read name_len and value_len */ |
5467 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); | 5401 | if (list_len < 0) { |
5468 | pSMB->DataCount = 0; | 5402 | cFYI(1, ("EA entry goes beyond length of list")); |
5469 | pSMB->DataOffset = 0; | 5403 | rc = -EIO; |
5470 | pSMB->SetupCount = 1; | 5404 | goto QAllEAsOut; |
5471 | pSMB->Reserved3 = 0; | 5405 | } |
5472 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); | ||
5473 | byte_count = params + 1 /* pad */ ; | ||
5474 | pSMB->TotalParameterCount = cpu_to_le16(params); | ||
5475 | pSMB->ParameterCount = pSMB->TotalParameterCount; | ||
5476 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); | ||
5477 | pSMB->Reserved4 = 0; | ||
5478 | pSMB->hdr.smb_buf_length += byte_count; | ||
5479 | pSMB->ByteCount = cpu_to_le16(byte_count); | ||
5480 | 5406 | ||
5481 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 5407 | name_len = temp_fea->name_len; |
5482 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 5408 | value_len = le16_to_cpu(temp_fea->value_len); |
5483 | if (rc) { | 5409 | list_len -= name_len + 1 + value_len; |
5484 | cFYI(1, ("Send error in Query EA = %d", rc)); | 5410 | if (list_len < 0) { |
5485 | } else { /* decode response */ | 5411 | cFYI(1, ("EA entry goes beyond length of list")); |
5486 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 5412 | rc = -EIO; |
5413 | goto QAllEAsOut; | ||
5414 | } | ||
5487 | 5415 | ||
5488 | /* BB also check enough total bytes returned */ | 5416 | if (ea_name) { |
5489 | /* BB we need to improve the validity checking | 5417 | if (strncmp(ea_name, temp_ptr, name_len) == 0) { |
5490 | of these trans2 responses */ | 5418 | temp_ptr += name_len + 1; |
5491 | if (rc || (pSMBr->ByteCount < 4)) | 5419 | rc = value_len; |
5492 | rc = -EIO; /* bad smb */ | 5420 | if (buf_size == 0) |
5493 | /* else if (pFindData){ | 5421 | goto QAllEAsOut; |
5494 | memcpy((char *) pFindData, | 5422 | if ((size_t)value_len > buf_size) { |
5495 | (char *) &pSMBr->hdr.Protocol + | 5423 | rc = -ERANGE; |
5496 | data_offset, kl); | 5424 | goto QAllEAsOut; |
5497 | }*/ else { | ||
5498 | /* check that length of list is not more than bcc */ | ||
5499 | /* check that each entry does not go beyond length | ||
5500 | of list */ | ||
5501 | /* check that each element of each entry does not | ||
5502 | go beyond end of list */ | ||
5503 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | ||
5504 | struct fealist *ea_response_data; | ||
5505 | rc = -ENODATA; | ||
5506 | /* validate_trans2_offsets() */ | ||
5507 | /* BB check if start of smb + data_offset > &bcc+ bcc*/ | ||
5508 | ea_response_data = (struct fealist *) | ||
5509 | (((char *) &pSMBr->hdr.Protocol) + | ||
5510 | data_offset); | ||
5511 | name_len = le32_to_cpu(ea_response_data->list_len); | ||
5512 | cFYI(1, ("ea length %d", name_len)); | ||
5513 | if (name_len <= 8) { | ||
5514 | /* returned EA size zeroed at top of function */ | ||
5515 | cFYI(1, ("empty EA list returned from server")); | ||
5516 | } else { | ||
5517 | /* account for ea list len */ | ||
5518 | name_len -= 4; | ||
5519 | temp_fea = ea_response_data->list; | ||
5520 | temp_ptr = (char *)temp_fea; | ||
5521 | /* loop through checking if we have a matching | ||
5522 | name and then return the associated value */ | ||
5523 | while (name_len > 0) { | ||
5524 | __u16 value_len; | ||
5525 | name_len -= 4; | ||
5526 | temp_ptr += 4; | ||
5527 | value_len = | ||
5528 | le16_to_cpu(temp_fea->value_len); | ||
5529 | /* BB validate that value_len falls within SMB, | ||
5530 | even though maximum for name_len is 255 */ | ||
5531 | if (memcmp(temp_fea->name, ea_name, | ||
5532 | temp_fea->name_len) == 0) { | ||
5533 | /* found a match */ | ||
5534 | rc = value_len; | ||
5535 | /* account for prefix user. and trailing null */ | ||
5536 | if (rc <= (int)buf_size) { | ||
5537 | memcpy(ea_value, | ||
5538 | temp_fea->name+temp_fea->name_len+1, | ||
5539 | rc); | ||
5540 | /* ea values, unlike ea | ||
5541 | names, are not null | ||
5542 | terminated */ | ||
5543 | } else if (buf_size == 0) { | ||
5544 | /* skip copy - calc size only */ | ||
5545 | } else { | ||
5546 | /* stop before overrun buffer */ | ||
5547 | rc = -ERANGE; | ||
5548 | } | ||
5549 | break; | ||
5550 | } | ||
5551 | name_len -= temp_fea->name_len; | ||
5552 | temp_ptr += temp_fea->name_len; | ||
5553 | /* account for trailing null */ | ||
5554 | name_len--; | ||
5555 | temp_ptr++; | ||
5556 | name_len -= value_len; | ||
5557 | temp_ptr += value_len; | ||
5558 | /* No trailing null to account for in | ||
5559 | value_len. Go on to next EA */ | ||
5560 | temp_fea = (struct fea *)temp_ptr; | ||
5561 | } | 5425 | } |
5426 | memcpy(EAData, temp_ptr, value_len); | ||
5427 | goto QAllEAsOut; | ||
5428 | } | ||
5429 | } else { | ||
5430 | /* account for prefix user. and trailing null */ | ||
5431 | rc += (5 + 1 + name_len); | ||
5432 | if (rc < (int) buf_size) { | ||
5433 | memcpy(EAData, "user.", 5); | ||
5434 | EAData += 5; | ||
5435 | memcpy(EAData, temp_ptr, name_len); | ||
5436 | EAData += name_len; | ||
5437 | /* null terminate name */ | ||
5438 | *EAData = 0; | ||
5439 | ++EAData; | ||
5440 | } else if (buf_size == 0) { | ||
5441 | /* skip copy - calc size only */ | ||
5442 | } else { | ||
5443 | /* stop before overrun buffer */ | ||
5444 | rc = -ERANGE; | ||
5445 | break; | ||
5562 | } | 5446 | } |
5563 | } | 5447 | } |
5448 | temp_ptr += name_len + 1 + value_len; | ||
5449 | temp_fea = (struct fea *)temp_ptr; | ||
5564 | } | 5450 | } |
5451 | |||
5452 | /* didn't find the named attribute */ | ||
5453 | if (ea_name) | ||
5454 | rc = -ENODATA; | ||
5455 | |||
5456 | QAllEAsOut: | ||
5565 | cifs_buf_release(pSMB); | 5457 | cifs_buf_release(pSMB); |
5566 | if (rc == -EAGAIN) | 5458 | if (rc == -EAGAIN) |
5567 | goto QEARetry; | 5459 | goto QAllEAsRetry; |
5568 | 5460 | ||
5569 | return (ssize_t)rc; | 5461 | return (ssize_t)rc; |
5570 | } | 5462 | } |
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 2e9e09ca0e30..45eb6cba793f 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -2388,13 +2388,13 @@ try_mount_again: | |||
2388 | */ | 2388 | */ |
2389 | cifs_put_tcp_session(srvTcp); | 2389 | cifs_put_tcp_session(srvTcp); |
2390 | 2390 | ||
2391 | down(&pSesInfo->sesSem); | 2391 | mutex_lock(&pSesInfo->session_mutex); |
2392 | if (pSesInfo->need_reconnect) { | 2392 | if (pSesInfo->need_reconnect) { |
2393 | cFYI(1, ("Session needs reconnect")); | 2393 | cFYI(1, ("Session needs reconnect")); |
2394 | rc = cifs_setup_session(xid, pSesInfo, | 2394 | rc = cifs_setup_session(xid, pSesInfo, |
2395 | cifs_sb->local_nls); | 2395 | cifs_sb->local_nls); |
2396 | } | 2396 | } |
2397 | up(&pSesInfo->sesSem); | 2397 | mutex_unlock(&pSesInfo->session_mutex); |
2398 | } else if (!rc) { | 2398 | } else if (!rc) { |
2399 | cFYI(1, ("Existing smb sess not found")); | 2399 | cFYI(1, ("Existing smb sess not found")); |
2400 | pSesInfo = sesInfoAlloc(); | 2400 | pSesInfo = sesInfoAlloc(); |
@@ -2437,12 +2437,12 @@ try_mount_again: | |||
2437 | } | 2437 | } |
2438 | pSesInfo->linux_uid = volume_info->linux_uid; | 2438 | pSesInfo->linux_uid = volume_info->linux_uid; |
2439 | pSesInfo->overrideSecFlg = volume_info->secFlg; | 2439 | pSesInfo->overrideSecFlg = volume_info->secFlg; |
2440 | down(&pSesInfo->sesSem); | 2440 | mutex_lock(&pSesInfo->session_mutex); |
2441 | 2441 | ||
2442 | /* BB FIXME need to pass vol->secFlgs BB */ | 2442 | /* BB FIXME need to pass vol->secFlgs BB */ |
2443 | rc = cifs_setup_session(xid, pSesInfo, | 2443 | rc = cifs_setup_session(xid, pSesInfo, |
2444 | cifs_sb->local_nls); | 2444 | cifs_sb->local_nls); |
2445 | up(&pSesInfo->sesSem); | 2445 | mutex_unlock(&pSesInfo->session_mutex); |
2446 | } | 2446 | } |
2447 | 2447 | ||
2448 | /* search for existing tcon to this server share */ | 2448 | /* search for existing tcon to this server share */ |
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index e3fda978f481..8bdbc818164c 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c | |||
@@ -111,6 +111,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr) | |||
111 | 111 | ||
112 | cifs_i->delete_pending = fattr->cf_flags & CIFS_FATTR_DELETE_PENDING; | 112 | cifs_i->delete_pending = fattr->cf_flags & CIFS_FATTR_DELETE_PENDING; |
113 | 113 | ||
114 | cifs_i->server_eof = fattr->cf_eof; | ||
114 | /* | 115 | /* |
115 | * Can't safely change the file size here if the client is writing to | 116 | * Can't safely change the file size here if the client is writing to |
116 | * it due to potential races. | 117 | * it due to potential races. |
@@ -366,7 +367,7 @@ static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path, | |||
366 | char ea_value[4]; | 367 | char ea_value[4]; |
367 | __u32 mode; | 368 | __u32 mode; |
368 | 369 | ||
369 | rc = CIFSSMBQueryEA(xid, cifs_sb->tcon, path, "SETFILEBITS", | 370 | rc = CIFSSMBQAllEAs(xid, cifs_sb->tcon, path, "SETFILEBITS", |
370 | ea_value, 4 /* size of buf */, cifs_sb->local_nls, | 371 | ea_value, 4 /* size of buf */, cifs_sb->local_nls, |
371 | cifs_sb->mnt_cifs_flags & | 372 | cifs_sb->mnt_cifs_flags & |
372 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 373 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index d27d4ec6579b..d1474996a812 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c | |||
@@ -79,7 +79,7 @@ sesInfoAlloc(void) | |||
79 | ++ret_buf->ses_count; | 79 | ++ret_buf->ses_count; |
80 | INIT_LIST_HEAD(&ret_buf->smb_ses_list); | 80 | INIT_LIST_HEAD(&ret_buf->smb_ses_list); |
81 | INIT_LIST_HEAD(&ret_buf->tcon_list); | 81 | INIT_LIST_HEAD(&ret_buf->tcon_list); |
82 | init_MUTEX(&ret_buf->sesSem); | 82 | mutex_init(&ret_buf->session_mutex); |
83 | } | 83 | } |
84 | return ret_buf; | 84 | return ret_buf; |
85 | } | 85 | } |
diff --git a/fs/cifs/xattr.c b/fs/cifs/xattr.c index a75afa3dd9e1..3e2ef0de1209 100644 --- a/fs/cifs/xattr.c +++ b/fs/cifs/xattr.c | |||
@@ -244,7 +244,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name, | |||
244 | /* revalidate/getattr then populate from inode */ | 244 | /* revalidate/getattr then populate from inode */ |
245 | } /* BB add else when above is implemented */ | 245 | } /* BB add else when above is implemented */ |
246 | ea_name += 5; /* skip past user. prefix */ | 246 | ea_name += 5; /* skip past user. prefix */ |
247 | rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value, | 247 | rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value, |
248 | buf_size, cifs_sb->local_nls, | 248 | buf_size, cifs_sb->local_nls, |
249 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 249 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
250 | } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) { | 250 | } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) { |
@@ -252,7 +252,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name, | |||
252 | goto get_ea_exit; | 252 | goto get_ea_exit; |
253 | 253 | ||
254 | ea_name += 4; /* skip past os2. prefix */ | 254 | ea_name += 4; /* skip past os2. prefix */ |
255 | rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value, | 255 | rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value, |
256 | buf_size, cifs_sb->local_nls, | 256 | buf_size, cifs_sb->local_nls, |
257 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 257 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
258 | } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS, | 258 | } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS, |
@@ -364,8 +364,8 @@ ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size) | |||
364 | /* if proc/fs/cifs/streamstoxattr is set then | 364 | /* if proc/fs/cifs/streamstoxattr is set then |
365 | search server for EAs or streams to | 365 | search server for EAs or streams to |
366 | returns as xattrs */ | 366 | returns as xattrs */ |
367 | rc = CIFSSMBQAllEAs(xid, pTcon, full_path, data, buf_size, | 367 | rc = CIFSSMBQAllEAs(xid, pTcon, full_path, NULL, data, |
368 | cifs_sb->local_nls, | 368 | buf_size, cifs_sb->local_nls, |
369 | cifs_sb->mnt_cifs_flags & | 369 | cifs_sb->mnt_cifs_flags & |
370 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 370 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
371 | 371 | ||
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 874d169a193e..4cedc91ec59d 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -1014,7 +1014,7 @@ struct ext4_sb_info { | |||
1014 | atomic_t s_lock_busy; | 1014 | atomic_t s_lock_busy; |
1015 | 1015 | ||
1016 | /* locality groups */ | 1016 | /* locality groups */ |
1017 | struct ext4_locality_group *s_locality_groups; | 1017 | struct ext4_locality_group __percpu *s_locality_groups; |
1018 | 1018 | ||
1019 | /* for write statistics */ | 1019 | /* for write statistics */ |
1020 | unsigned long s_sectors_written_start; | 1020 | unsigned long s_sectors_written_start; |
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 51d9e33d634f..eb7e9423691f 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c | |||
@@ -865,13 +865,10 @@ static int fuse_notify_inval_inode(struct fuse_conn *fc, unsigned int size, | |||
865 | 865 | ||
866 | down_read(&fc->killsb); | 866 | down_read(&fc->killsb); |
867 | err = -ENOENT; | 867 | err = -ENOENT; |
868 | if (!fc->sb) | 868 | if (fc->sb) { |
869 | goto err_unlock; | 869 | err = fuse_reverse_inval_inode(fc->sb, outarg.ino, |
870 | 870 | outarg.off, outarg.len); | |
871 | err = fuse_reverse_inval_inode(fc->sb, outarg.ino, | 871 | } |
872 | outarg.off, outarg.len); | ||
873 | |||
874 | err_unlock: | ||
875 | up_read(&fc->killsb); | 872 | up_read(&fc->killsb); |
876 | return err; | 873 | return err; |
877 | 874 | ||
@@ -884,10 +881,15 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size, | |||
884 | struct fuse_copy_state *cs) | 881 | struct fuse_copy_state *cs) |
885 | { | 882 | { |
886 | struct fuse_notify_inval_entry_out outarg; | 883 | struct fuse_notify_inval_entry_out outarg; |
887 | int err = -EINVAL; | 884 | int err = -ENOMEM; |
888 | char buf[FUSE_NAME_MAX+1]; | 885 | char *buf; |
889 | struct qstr name; | 886 | struct qstr name; |
890 | 887 | ||
888 | buf = kzalloc(FUSE_NAME_MAX + 1, GFP_KERNEL); | ||
889 | if (!buf) | ||
890 | goto err; | ||
891 | |||
892 | err = -EINVAL; | ||
891 | if (size < sizeof(outarg)) | 893 | if (size < sizeof(outarg)) |
892 | goto err; | 894 | goto err; |
893 | 895 | ||
@@ -910,16 +912,14 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size, | |||
910 | 912 | ||
911 | down_read(&fc->killsb); | 913 | down_read(&fc->killsb); |
912 | err = -ENOENT; | 914 | err = -ENOENT; |
913 | if (!fc->sb) | 915 | if (fc->sb) |
914 | goto err_unlock; | 916 | err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name); |
915 | |||
916 | err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name); | ||
917 | |||
918 | err_unlock: | ||
919 | up_read(&fc->killsb); | 917 | up_read(&fc->killsb); |
918 | kfree(buf); | ||
920 | return err; | 919 | return err; |
921 | 920 | ||
922 | err: | 921 | err: |
922 | kfree(buf); | ||
923 | fuse_copy_finish(cs); | 923 | fuse_copy_finish(cs); |
924 | return err; | 924 | return err; |
925 | } | 925 | } |
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c index 7b8da9415267..0c1d0b82dcf1 100644 --- a/fs/gfs2/aops.c +++ b/fs/gfs2/aops.c | |||
@@ -1061,8 +1061,8 @@ out: | |||
1061 | 1061 | ||
1062 | int gfs2_releasepage(struct page *page, gfp_t gfp_mask) | 1062 | int gfs2_releasepage(struct page *page, gfp_t gfp_mask) |
1063 | { | 1063 | { |
1064 | struct inode *aspace = page->mapping->host; | 1064 | struct address_space *mapping = page->mapping; |
1065 | struct gfs2_sbd *sdp = aspace->i_sb->s_fs_info; | 1065 | struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping); |
1066 | struct buffer_head *bh, *head; | 1066 | struct buffer_head *bh, *head; |
1067 | struct gfs2_bufdata *bd; | 1067 | struct gfs2_bufdata *bd; |
1068 | 1068 | ||
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index f42663325931..454d4b4eb36b 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <linux/list.h> | 19 | #include <linux/list.h> |
20 | #include <linux/wait.h> | 20 | #include <linux/wait.h> |
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/rwsem.h> | ||
23 | #include <asm/uaccess.h> | 22 | #include <asm/uaccess.h> |
24 | #include <linux/seq_file.h> | 23 | #include <linux/seq_file.h> |
25 | #include <linux/debugfs.h> | 24 | #include <linux/debugfs.h> |
@@ -60,7 +59,6 @@ static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl); | |||
60 | #define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) { __dump_glock(NULL, gl); BUG(); } } while(0) | 59 | #define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) { __dump_glock(NULL, gl); BUG(); } } while(0) |
61 | static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target); | 60 | static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target); |
62 | 61 | ||
63 | static DECLARE_RWSEM(gfs2_umount_flush_sem); | ||
64 | static struct dentry *gfs2_root; | 62 | static struct dentry *gfs2_root; |
65 | static struct workqueue_struct *glock_workqueue; | 63 | static struct workqueue_struct *glock_workqueue; |
66 | struct workqueue_struct *gfs2_delete_workqueue; | 64 | struct workqueue_struct *gfs2_delete_workqueue; |
@@ -154,12 +152,14 @@ static unsigned int gl_hash(const struct gfs2_sbd *sdp, | |||
154 | static void glock_free(struct gfs2_glock *gl) | 152 | static void glock_free(struct gfs2_glock *gl) |
155 | { | 153 | { |
156 | struct gfs2_sbd *sdp = gl->gl_sbd; | 154 | struct gfs2_sbd *sdp = gl->gl_sbd; |
157 | struct inode *aspace = gl->gl_aspace; | 155 | struct address_space *mapping = gfs2_glock2aspace(gl); |
156 | struct kmem_cache *cachep = gfs2_glock_cachep; | ||
158 | 157 | ||
159 | if (aspace) | 158 | GLOCK_BUG_ON(gl, mapping && mapping->nrpages); |
160 | gfs2_aspace_put(aspace); | ||
161 | trace_gfs2_glock_put(gl); | 159 | trace_gfs2_glock_put(gl); |
162 | sdp->sd_lockstruct.ls_ops->lm_put_lock(gfs2_glock_cachep, gl); | 160 | if (mapping) |
161 | cachep = gfs2_glock_aspace_cachep; | ||
162 | sdp->sd_lockstruct.ls_ops->lm_put_lock(cachep, gl); | ||
163 | } | 163 | } |
164 | 164 | ||
165 | /** | 165 | /** |
@@ -712,7 +712,6 @@ static void glock_work_func(struct work_struct *work) | |||
712 | finish_xmote(gl, gl->gl_reply); | 712 | finish_xmote(gl, gl->gl_reply); |
713 | drop_ref = 1; | 713 | drop_ref = 1; |
714 | } | 714 | } |
715 | down_read(&gfs2_umount_flush_sem); | ||
716 | spin_lock(&gl->gl_spin); | 715 | spin_lock(&gl->gl_spin); |
717 | if (test_and_clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && | 716 | if (test_and_clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && |
718 | gl->gl_state != LM_ST_UNLOCKED && | 717 | gl->gl_state != LM_ST_UNLOCKED && |
@@ -725,7 +724,6 @@ static void glock_work_func(struct work_struct *work) | |||
725 | } | 724 | } |
726 | run_queue(gl, 0); | 725 | run_queue(gl, 0); |
727 | spin_unlock(&gl->gl_spin); | 726 | spin_unlock(&gl->gl_spin); |
728 | up_read(&gfs2_umount_flush_sem); | ||
729 | if (!delay || | 727 | if (!delay || |
730 | queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0) | 728 | queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0) |
731 | gfs2_glock_put(gl); | 729 | gfs2_glock_put(gl); |
@@ -750,10 +748,11 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, | |||
750 | const struct gfs2_glock_operations *glops, int create, | 748 | const struct gfs2_glock_operations *glops, int create, |
751 | struct gfs2_glock **glp) | 749 | struct gfs2_glock **glp) |
752 | { | 750 | { |
751 | struct super_block *s = sdp->sd_vfs; | ||
753 | struct lm_lockname name = { .ln_number = number, .ln_type = glops->go_type }; | 752 | struct lm_lockname name = { .ln_number = number, .ln_type = glops->go_type }; |
754 | struct gfs2_glock *gl, *tmp; | 753 | struct gfs2_glock *gl, *tmp; |
755 | unsigned int hash = gl_hash(sdp, &name); | 754 | unsigned int hash = gl_hash(sdp, &name); |
756 | int error; | 755 | struct address_space *mapping; |
757 | 756 | ||
758 | read_lock(gl_lock_addr(hash)); | 757 | read_lock(gl_lock_addr(hash)); |
759 | gl = search_bucket(hash, sdp, &name); | 758 | gl = search_bucket(hash, sdp, &name); |
@@ -765,7 +764,10 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, | |||
765 | if (!create) | 764 | if (!create) |
766 | return -ENOENT; | 765 | return -ENOENT; |
767 | 766 | ||
768 | gl = kmem_cache_alloc(gfs2_glock_cachep, GFP_KERNEL); | 767 | if (glops->go_flags & GLOF_ASPACE) |
768 | gl = kmem_cache_alloc(gfs2_glock_aspace_cachep, GFP_KERNEL); | ||
769 | else | ||
770 | gl = kmem_cache_alloc(gfs2_glock_cachep, GFP_KERNEL); | ||
769 | if (!gl) | 771 | if (!gl) |
770 | return -ENOMEM; | 772 | return -ENOMEM; |
771 | 773 | ||
@@ -784,18 +786,18 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, | |||
784 | gl->gl_tchange = jiffies; | 786 | gl->gl_tchange = jiffies; |
785 | gl->gl_object = NULL; | 787 | gl->gl_object = NULL; |
786 | gl->gl_sbd = sdp; | 788 | gl->gl_sbd = sdp; |
787 | gl->gl_aspace = NULL; | ||
788 | INIT_DELAYED_WORK(&gl->gl_work, glock_work_func); | 789 | INIT_DELAYED_WORK(&gl->gl_work, glock_work_func); |
789 | INIT_WORK(&gl->gl_delete, delete_work_func); | 790 | INIT_WORK(&gl->gl_delete, delete_work_func); |
790 | 791 | ||
791 | /* If this glock protects actual on-disk data or metadata blocks, | 792 | mapping = gfs2_glock2aspace(gl); |
792 | create a VFS inode to manage the pages/buffers holding them. */ | 793 | if (mapping) { |
793 | if (glops == &gfs2_inode_glops || glops == &gfs2_rgrp_glops) { | 794 | mapping->a_ops = &gfs2_meta_aops; |
794 | gl->gl_aspace = gfs2_aspace_get(sdp); | 795 | mapping->host = s->s_bdev->bd_inode; |
795 | if (!gl->gl_aspace) { | 796 | mapping->flags = 0; |
796 | error = -ENOMEM; | 797 | mapping_set_gfp_mask(mapping, GFP_NOFS); |
797 | goto fail; | 798 | mapping->assoc_mapping = NULL; |
798 | } | 799 | mapping->backing_dev_info = s->s_bdi; |
800 | mapping->writeback_index = 0; | ||
799 | } | 801 | } |
800 | 802 | ||
801 | write_lock(gl_lock_addr(hash)); | 803 | write_lock(gl_lock_addr(hash)); |
@@ -812,10 +814,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, | |||
812 | *glp = gl; | 814 | *glp = gl; |
813 | 815 | ||
814 | return 0; | 816 | return 0; |
815 | |||
816 | fail: | ||
817 | kmem_cache_free(gfs2_glock_cachep, gl); | ||
818 | return error; | ||
819 | } | 817 | } |
820 | 818 | ||
821 | /** | 819 | /** |
@@ -1510,35 +1508,10 @@ void gfs2_glock_thaw(struct gfs2_sbd *sdp) | |||
1510 | 1508 | ||
1511 | void gfs2_gl_hash_clear(struct gfs2_sbd *sdp) | 1509 | void gfs2_gl_hash_clear(struct gfs2_sbd *sdp) |
1512 | { | 1510 | { |
1513 | unsigned long t; | ||
1514 | unsigned int x; | 1511 | unsigned int x; |
1515 | int cont; | ||
1516 | 1512 | ||
1517 | t = jiffies; | 1513 | for (x = 0; x < GFS2_GL_HASH_SIZE; x++) |
1518 | 1514 | examine_bucket(clear_glock, sdp, x); | |
1519 | for (;;) { | ||
1520 | cont = 0; | ||
1521 | for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { | ||
1522 | if (examine_bucket(clear_glock, sdp, x)) | ||
1523 | cont = 1; | ||
1524 | } | ||
1525 | |||
1526 | if (!cont) | ||
1527 | break; | ||
1528 | |||
1529 | if (time_after_eq(jiffies, | ||
1530 | t + gfs2_tune_get(sdp, gt_stall_secs) * HZ)) { | ||
1531 | fs_warn(sdp, "Unmount seems to be stalled. " | ||
1532 | "Dumping lock state...\n"); | ||
1533 | gfs2_dump_lockstate(sdp); | ||
1534 | t = jiffies; | ||
1535 | } | ||
1536 | |||
1537 | down_write(&gfs2_umount_flush_sem); | ||
1538 | invalidate_inodes(sdp->sd_vfs); | ||
1539 | up_write(&gfs2_umount_flush_sem); | ||
1540 | msleep(10); | ||
1541 | } | ||
1542 | flush_workqueue(glock_workqueue); | 1515 | flush_workqueue(glock_workqueue); |
1543 | wait_event(sdp->sd_glock_wait, atomic_read(&sdp->sd_glock_disposal) == 0); | 1516 | wait_event(sdp->sd_glock_wait, atomic_read(&sdp->sd_glock_disposal) == 0); |
1544 | gfs2_dump_lockstate(sdp); | 1517 | gfs2_dump_lockstate(sdp); |
@@ -1685,7 +1658,7 @@ static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl) | |||
1685 | dtime *= 1000000/HZ; /* demote time in uSec */ | 1658 | dtime *= 1000000/HZ; /* demote time in uSec */ |
1686 | if (!test_bit(GLF_DEMOTE, &gl->gl_flags)) | 1659 | if (!test_bit(GLF_DEMOTE, &gl->gl_flags)) |
1687 | dtime = 0; | 1660 | dtime = 0; |
1688 | gfs2_print_dbg(seq, "G: s:%s n:%u/%llu f:%s t:%s d:%s/%llu a:%d r:%d\n", | 1661 | gfs2_print_dbg(seq, "G: s:%s n:%u/%llx f:%s t:%s d:%s/%llu a:%d r:%d\n", |
1689 | state2str(gl->gl_state), | 1662 | state2str(gl->gl_state), |
1690 | gl->gl_name.ln_type, | 1663 | gl->gl_name.ln_type, |
1691 | (unsigned long long)gl->gl_name.ln_number, | 1664 | (unsigned long long)gl->gl_name.ln_number, |
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h index c0262faf4725..2bda1911b156 100644 --- a/fs/gfs2/glock.h +++ b/fs/gfs2/glock.h | |||
@@ -180,6 +180,13 @@ static inline int gfs2_glock_is_held_shrd(struct gfs2_glock *gl) | |||
180 | return gl->gl_state == LM_ST_SHARED; | 180 | return gl->gl_state == LM_ST_SHARED; |
181 | } | 181 | } |
182 | 182 | ||
183 | static inline struct address_space *gfs2_glock2aspace(struct gfs2_glock *gl) | ||
184 | { | ||
185 | if (gl->gl_ops->go_flags & GLOF_ASPACE) | ||
186 | return (struct address_space *)(gl + 1); | ||
187 | return NULL; | ||
188 | } | ||
189 | |||
183 | int gfs2_glock_get(struct gfs2_sbd *sdp, | 190 | int gfs2_glock_get(struct gfs2_sbd *sdp, |
184 | u64 number, const struct gfs2_glock_operations *glops, | 191 | u64 number, const struct gfs2_glock_operations *glops, |
185 | int create, struct gfs2_glock **glp); | 192 | int create, struct gfs2_glock **glp); |
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 78554acc0605..38e3749d476c 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c | |||
@@ -87,7 +87,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl) | |||
87 | 87 | ||
88 | static void rgrp_go_sync(struct gfs2_glock *gl) | 88 | static void rgrp_go_sync(struct gfs2_glock *gl) |
89 | { | 89 | { |
90 | struct address_space *metamapping = gl->gl_aspace->i_mapping; | 90 | struct address_space *metamapping = gfs2_glock2aspace(gl); |
91 | int error; | 91 | int error; |
92 | 92 | ||
93 | if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags)) | 93 | if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags)) |
@@ -113,7 +113,7 @@ static void rgrp_go_sync(struct gfs2_glock *gl) | |||
113 | 113 | ||
114 | static void rgrp_go_inval(struct gfs2_glock *gl, int flags) | 114 | static void rgrp_go_inval(struct gfs2_glock *gl, int flags) |
115 | { | 115 | { |
116 | struct address_space *mapping = gl->gl_aspace->i_mapping; | 116 | struct address_space *mapping = gfs2_glock2aspace(gl); |
117 | 117 | ||
118 | BUG_ON(!(flags & DIO_METADATA)); | 118 | BUG_ON(!(flags & DIO_METADATA)); |
119 | gfs2_assert_withdraw(gl->gl_sbd, !atomic_read(&gl->gl_ail_count)); | 119 | gfs2_assert_withdraw(gl->gl_sbd, !atomic_read(&gl->gl_ail_count)); |
@@ -134,7 +134,7 @@ static void rgrp_go_inval(struct gfs2_glock *gl, int flags) | |||
134 | static void inode_go_sync(struct gfs2_glock *gl) | 134 | static void inode_go_sync(struct gfs2_glock *gl) |
135 | { | 135 | { |
136 | struct gfs2_inode *ip = gl->gl_object; | 136 | struct gfs2_inode *ip = gl->gl_object; |
137 | struct address_space *metamapping = gl->gl_aspace->i_mapping; | 137 | struct address_space *metamapping = gfs2_glock2aspace(gl); |
138 | int error; | 138 | int error; |
139 | 139 | ||
140 | if (ip && !S_ISREG(ip->i_inode.i_mode)) | 140 | if (ip && !S_ISREG(ip->i_inode.i_mode)) |
@@ -183,7 +183,7 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags) | |||
183 | gfs2_assert_withdraw(gl->gl_sbd, !atomic_read(&gl->gl_ail_count)); | 183 | gfs2_assert_withdraw(gl->gl_sbd, !atomic_read(&gl->gl_ail_count)); |
184 | 184 | ||
185 | if (flags & DIO_METADATA) { | 185 | if (flags & DIO_METADATA) { |
186 | struct address_space *mapping = gl->gl_aspace->i_mapping; | 186 | struct address_space *mapping = gfs2_glock2aspace(gl); |
187 | truncate_inode_pages(mapping, 0); | 187 | truncate_inode_pages(mapping, 0); |
188 | if (ip) { | 188 | if (ip) { |
189 | set_bit(GIF_INVALID, &ip->i_flags); | 189 | set_bit(GIF_INVALID, &ip->i_flags); |
@@ -282,7 +282,8 @@ static int inode_go_dump(struct seq_file *seq, const struct gfs2_glock *gl) | |||
282 | 282 | ||
283 | static int rgrp_go_demote_ok(const struct gfs2_glock *gl) | 283 | static int rgrp_go_demote_ok(const struct gfs2_glock *gl) |
284 | { | 284 | { |
285 | return !gl->gl_aspace->i_mapping->nrpages; | 285 | const struct address_space *mapping = (const struct address_space *)(gl + 1); |
286 | return !mapping->nrpages; | ||
286 | } | 287 | } |
287 | 288 | ||
288 | /** | 289 | /** |
@@ -387,8 +388,7 @@ static void iopen_go_callback(struct gfs2_glock *gl) | |||
387 | struct gfs2_inode *ip = (struct gfs2_inode *)gl->gl_object; | 388 | struct gfs2_inode *ip = (struct gfs2_inode *)gl->gl_object; |
388 | 389 | ||
389 | if (gl->gl_demote_state == LM_ST_UNLOCKED && | 390 | if (gl->gl_demote_state == LM_ST_UNLOCKED && |
390 | gl->gl_state == LM_ST_SHARED && | 391 | gl->gl_state == LM_ST_SHARED && ip) { |
391 | ip && test_bit(GIF_USER, &ip->i_flags)) { | ||
392 | gfs2_glock_hold(gl); | 392 | gfs2_glock_hold(gl); |
393 | if (queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0) | 393 | if (queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0) |
394 | gfs2_glock_put_nolock(gl); | 394 | gfs2_glock_put_nolock(gl); |
@@ -407,6 +407,7 @@ const struct gfs2_glock_operations gfs2_inode_glops = { | |||
407 | .go_dump = inode_go_dump, | 407 | .go_dump = inode_go_dump, |
408 | .go_type = LM_TYPE_INODE, | 408 | .go_type = LM_TYPE_INODE, |
409 | .go_min_hold_time = HZ / 5, | 409 | .go_min_hold_time = HZ / 5, |
410 | .go_flags = GLOF_ASPACE, | ||
410 | }; | 411 | }; |
411 | 412 | ||
412 | const struct gfs2_glock_operations gfs2_rgrp_glops = { | 413 | const struct gfs2_glock_operations gfs2_rgrp_glops = { |
@@ -418,6 +419,7 @@ const struct gfs2_glock_operations gfs2_rgrp_glops = { | |||
418 | .go_dump = gfs2_rgrp_dump, | 419 | .go_dump = gfs2_rgrp_dump, |
419 | .go_type = LM_TYPE_RGRP, | 420 | .go_type = LM_TYPE_RGRP, |
420 | .go_min_hold_time = HZ / 5, | 421 | .go_min_hold_time = HZ / 5, |
422 | .go_flags = GLOF_ASPACE, | ||
421 | }; | 423 | }; |
422 | 424 | ||
423 | const struct gfs2_glock_operations gfs2_trans_glops = { | 425 | const struct gfs2_glock_operations gfs2_trans_glops = { |
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index bc0ad158e6b4..b8025e51cabf 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h | |||
@@ -162,6 +162,8 @@ struct gfs2_glock_operations { | |||
162 | void (*go_callback) (struct gfs2_glock *gl); | 162 | void (*go_callback) (struct gfs2_glock *gl); |
163 | const int go_type; | 163 | const int go_type; |
164 | const unsigned long go_min_hold_time; | 164 | const unsigned long go_min_hold_time; |
165 | const unsigned long go_flags; | ||
166 | #define GLOF_ASPACE 1 | ||
165 | }; | 167 | }; |
166 | 168 | ||
167 | enum { | 169 | enum { |
@@ -225,7 +227,6 @@ struct gfs2_glock { | |||
225 | 227 | ||
226 | struct gfs2_sbd *gl_sbd; | 228 | struct gfs2_sbd *gl_sbd; |
227 | 229 | ||
228 | struct inode *gl_aspace; | ||
229 | struct list_head gl_ail_list; | 230 | struct list_head gl_ail_list; |
230 | atomic_t gl_ail_count; | 231 | atomic_t gl_ail_count; |
231 | struct delayed_work gl_work; | 232 | struct delayed_work gl_work; |
@@ -258,7 +259,6 @@ enum { | |||
258 | GIF_INVALID = 0, | 259 | GIF_INVALID = 0, |
259 | GIF_QD_LOCKED = 1, | 260 | GIF_QD_LOCKED = 1, |
260 | GIF_SW_PAGED = 3, | 261 | GIF_SW_PAGED = 3, |
261 | GIF_USER = 4, /* user inode, not metadata addr space */ | ||
262 | }; | 262 | }; |
263 | 263 | ||
264 | 264 | ||
@@ -451,7 +451,6 @@ struct gfs2_tune { | |||
451 | unsigned int gt_quota_quantum; /* Secs between syncs to quota file */ | 451 | unsigned int gt_quota_quantum; /* Secs between syncs to quota file */ |
452 | unsigned int gt_new_files_jdata; | 452 | unsigned int gt_new_files_jdata; |
453 | unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */ | 453 | unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */ |
454 | unsigned int gt_stall_secs; /* Detects trouble! */ | ||
455 | unsigned int gt_complain_secs; | 454 | unsigned int gt_complain_secs; |
456 | unsigned int gt_statfs_quantum; | 455 | unsigned int gt_statfs_quantum; |
457 | unsigned int gt_statfs_slow; | 456 | unsigned int gt_statfs_slow; |
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 6e220f4eee7d..b1bf2694fb2b 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c | |||
@@ -45,7 +45,7 @@ static int iget_test(struct inode *inode, void *opaque) | |||
45 | struct gfs2_inode *ip = GFS2_I(inode); | 45 | struct gfs2_inode *ip = GFS2_I(inode); |
46 | u64 *no_addr = opaque; | 46 | u64 *no_addr = opaque; |
47 | 47 | ||
48 | if (ip->i_no_addr == *no_addr && test_bit(GIF_USER, &ip->i_flags)) | 48 | if (ip->i_no_addr == *no_addr) |
49 | return 1; | 49 | return 1; |
50 | 50 | ||
51 | return 0; | 51 | return 0; |
@@ -58,7 +58,6 @@ static int iget_set(struct inode *inode, void *opaque) | |||
58 | 58 | ||
59 | inode->i_ino = (unsigned long)*no_addr; | 59 | inode->i_ino = (unsigned long)*no_addr; |
60 | ip->i_no_addr = *no_addr; | 60 | ip->i_no_addr = *no_addr; |
61 | set_bit(GIF_USER, &ip->i_flags); | ||
62 | return 0; | 61 | return 0; |
63 | } | 62 | } |
64 | 63 | ||
@@ -84,7 +83,7 @@ static int iget_skip_test(struct inode *inode, void *opaque) | |||
84 | struct gfs2_inode *ip = GFS2_I(inode); | 83 | struct gfs2_inode *ip = GFS2_I(inode); |
85 | struct gfs2_skip_data *data = opaque; | 84 | struct gfs2_skip_data *data = opaque; |
86 | 85 | ||
87 | if (ip->i_no_addr == data->no_addr && test_bit(GIF_USER, &ip->i_flags)){ | 86 | if (ip->i_no_addr == data->no_addr) { |
88 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)){ | 87 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)){ |
89 | data->skipped = 1; | 88 | data->skipped = 1; |
90 | return 0; | 89 | return 0; |
@@ -103,7 +102,6 @@ static int iget_skip_set(struct inode *inode, void *opaque) | |||
103 | return 1; | 102 | return 1; |
104 | inode->i_ino = (unsigned long)(data->no_addr); | 103 | inode->i_ino = (unsigned long)(data->no_addr); |
105 | ip->i_no_addr = data->no_addr; | 104 | ip->i_no_addr = data->no_addr; |
106 | set_bit(GIF_USER, &ip->i_flags); | ||
107 | return 0; | 105 | return 0; |
108 | } | 106 | } |
109 | 107 | ||
diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c index 0e5e0e7022e5..569b46240f61 100644 --- a/fs/gfs2/lock_dlm.c +++ b/fs/gfs2/lock_dlm.c | |||
@@ -30,7 +30,10 @@ static void gdlm_ast(void *arg) | |||
30 | 30 | ||
31 | switch (gl->gl_lksb.sb_status) { | 31 | switch (gl->gl_lksb.sb_status) { |
32 | case -DLM_EUNLOCK: /* Unlocked, so glock can be freed */ | 32 | case -DLM_EUNLOCK: /* Unlocked, so glock can be freed */ |
33 | kmem_cache_free(gfs2_glock_cachep, gl); | 33 | if (gl->gl_ops->go_flags & GLOF_ASPACE) |
34 | kmem_cache_free(gfs2_glock_aspace_cachep, gl); | ||
35 | else | ||
36 | kmem_cache_free(gfs2_glock_cachep, gl); | ||
34 | if (atomic_dec_and_test(&sdp->sd_glock_disposal)) | 37 | if (atomic_dec_and_test(&sdp->sd_glock_disposal)) |
35 | wake_up(&sdp->sd_glock_wait); | 38 | wake_up(&sdp->sd_glock_wait); |
36 | return; | 39 | return; |
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index de97632ba32f..adc260fbea90 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c | |||
@@ -528,9 +528,9 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) | |||
528 | gfs2_pin(sdp, bd->bd_bh); | 528 | gfs2_pin(sdp, bd->bd_bh); |
529 | tr->tr_num_databuf_new++; | 529 | tr->tr_num_databuf_new++; |
530 | sdp->sd_log_num_databuf++; | 530 | sdp->sd_log_num_databuf++; |
531 | list_add(&le->le_list, &sdp->sd_log_le_databuf); | 531 | list_add_tail(&le->le_list, &sdp->sd_log_le_databuf); |
532 | } else { | 532 | } else { |
533 | list_add(&le->le_list, &sdp->sd_log_le_ordered); | 533 | list_add_tail(&le->le_list, &sdp->sd_log_le_ordered); |
534 | } | 534 | } |
535 | out: | 535 | out: |
536 | gfs2_log_unlock(sdp); | 536 | gfs2_log_unlock(sdp); |
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index 5b31f7741a8f..a88fadc704bb 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c | |||
@@ -52,6 +52,22 @@ static void gfs2_init_glock_once(void *foo) | |||
52 | atomic_set(&gl->gl_ail_count, 0); | 52 | atomic_set(&gl->gl_ail_count, 0); |
53 | } | 53 | } |
54 | 54 | ||
55 | static void gfs2_init_gl_aspace_once(void *foo) | ||
56 | { | ||
57 | struct gfs2_glock *gl = foo; | ||
58 | struct address_space *mapping = (struct address_space *)(gl + 1); | ||
59 | |||
60 | gfs2_init_glock_once(gl); | ||
61 | memset(mapping, 0, sizeof(*mapping)); | ||
62 | INIT_RADIX_TREE(&mapping->page_tree, GFP_ATOMIC); | ||
63 | spin_lock_init(&mapping->tree_lock); | ||
64 | spin_lock_init(&mapping->i_mmap_lock); | ||
65 | INIT_LIST_HEAD(&mapping->private_list); | ||
66 | spin_lock_init(&mapping->private_lock); | ||
67 | INIT_RAW_PRIO_TREE_ROOT(&mapping->i_mmap); | ||
68 | INIT_LIST_HEAD(&mapping->i_mmap_nonlinear); | ||
69 | } | ||
70 | |||
55 | /** | 71 | /** |
56 | * init_gfs2_fs - Register GFS2 as a filesystem | 72 | * init_gfs2_fs - Register GFS2 as a filesystem |
57 | * | 73 | * |
@@ -78,6 +94,14 @@ static int __init init_gfs2_fs(void) | |||
78 | if (!gfs2_glock_cachep) | 94 | if (!gfs2_glock_cachep) |
79 | goto fail; | 95 | goto fail; |
80 | 96 | ||
97 | gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock (aspace)", | ||
98 | sizeof(struct gfs2_glock) + | ||
99 | sizeof(struct address_space), | ||
100 | 0, 0, gfs2_init_gl_aspace_once); | ||
101 | |||
102 | if (!gfs2_glock_aspace_cachep) | ||
103 | goto fail; | ||
104 | |||
81 | gfs2_inode_cachep = kmem_cache_create("gfs2_inode", | 105 | gfs2_inode_cachep = kmem_cache_create("gfs2_inode", |
82 | sizeof(struct gfs2_inode), | 106 | sizeof(struct gfs2_inode), |
83 | 0, SLAB_RECLAIM_ACCOUNT| | 107 | 0, SLAB_RECLAIM_ACCOUNT| |
@@ -144,6 +168,9 @@ fail: | |||
144 | if (gfs2_inode_cachep) | 168 | if (gfs2_inode_cachep) |
145 | kmem_cache_destroy(gfs2_inode_cachep); | 169 | kmem_cache_destroy(gfs2_inode_cachep); |
146 | 170 | ||
171 | if (gfs2_glock_aspace_cachep) | ||
172 | kmem_cache_destroy(gfs2_glock_aspace_cachep); | ||
173 | |||
147 | if (gfs2_glock_cachep) | 174 | if (gfs2_glock_cachep) |
148 | kmem_cache_destroy(gfs2_glock_cachep); | 175 | kmem_cache_destroy(gfs2_glock_cachep); |
149 | 176 | ||
@@ -169,6 +196,7 @@ static void __exit exit_gfs2_fs(void) | |||
169 | kmem_cache_destroy(gfs2_rgrpd_cachep); | 196 | kmem_cache_destroy(gfs2_rgrpd_cachep); |
170 | kmem_cache_destroy(gfs2_bufdata_cachep); | 197 | kmem_cache_destroy(gfs2_bufdata_cachep); |
171 | kmem_cache_destroy(gfs2_inode_cachep); | 198 | kmem_cache_destroy(gfs2_inode_cachep); |
199 | kmem_cache_destroy(gfs2_glock_aspace_cachep); | ||
172 | kmem_cache_destroy(gfs2_glock_cachep); | 200 | kmem_cache_destroy(gfs2_glock_cachep); |
173 | 201 | ||
174 | gfs2_sys_uninit(); | 202 | gfs2_sys_uninit(); |
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index 6f68a5f18eb8..0bb12c80937a 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c | |||
@@ -93,49 +93,13 @@ static int gfs2_aspace_writepage(struct page *page, struct writeback_control *wb | |||
93 | return err; | 93 | return err; |
94 | } | 94 | } |
95 | 95 | ||
96 | static const struct address_space_operations aspace_aops = { | 96 | const struct address_space_operations gfs2_meta_aops = { |
97 | .writepage = gfs2_aspace_writepage, | 97 | .writepage = gfs2_aspace_writepage, |
98 | .releasepage = gfs2_releasepage, | 98 | .releasepage = gfs2_releasepage, |
99 | .sync_page = block_sync_page, | 99 | .sync_page = block_sync_page, |
100 | }; | 100 | }; |
101 | 101 | ||
102 | /** | 102 | /** |
103 | * gfs2_aspace_get - Create and initialize a struct inode structure | ||
104 | * @sdp: the filesystem the aspace is in | ||
105 | * | ||
106 | * Right now a struct inode is just a struct inode. Maybe Linux | ||
107 | * will supply a more lightweight address space construct (that works) | ||
108 | * in the future. | ||
109 | * | ||
110 | * Make sure pages/buffers in this aspace aren't in high memory. | ||
111 | * | ||
112 | * Returns: the aspace | ||
113 | */ | ||
114 | |||
115 | struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp) | ||
116 | { | ||
117 | struct inode *aspace; | ||
118 | struct gfs2_inode *ip; | ||
119 | |||
120 | aspace = new_inode(sdp->sd_vfs); | ||
121 | if (aspace) { | ||
122 | mapping_set_gfp_mask(aspace->i_mapping, GFP_NOFS); | ||
123 | aspace->i_mapping->a_ops = &aspace_aops; | ||
124 | aspace->i_size = MAX_LFS_FILESIZE; | ||
125 | ip = GFS2_I(aspace); | ||
126 | clear_bit(GIF_USER, &ip->i_flags); | ||
127 | insert_inode_hash(aspace); | ||
128 | } | ||
129 | return aspace; | ||
130 | } | ||
131 | |||
132 | void gfs2_aspace_put(struct inode *aspace) | ||
133 | { | ||
134 | remove_inode_hash(aspace); | ||
135 | iput(aspace); | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * gfs2_meta_sync - Sync all buffers associated with a glock | 103 | * gfs2_meta_sync - Sync all buffers associated with a glock |
140 | * @gl: The glock | 104 | * @gl: The glock |
141 | * | 105 | * |
@@ -143,7 +107,7 @@ void gfs2_aspace_put(struct inode *aspace) | |||
143 | 107 | ||
144 | void gfs2_meta_sync(struct gfs2_glock *gl) | 108 | void gfs2_meta_sync(struct gfs2_glock *gl) |
145 | { | 109 | { |
146 | struct address_space *mapping = gl->gl_aspace->i_mapping; | 110 | struct address_space *mapping = gfs2_glock2aspace(gl); |
147 | int error; | 111 | int error; |
148 | 112 | ||
149 | filemap_fdatawrite(mapping); | 113 | filemap_fdatawrite(mapping); |
@@ -164,7 +128,7 @@ void gfs2_meta_sync(struct gfs2_glock *gl) | |||
164 | 128 | ||
165 | struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create) | 129 | struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create) |
166 | { | 130 | { |
167 | struct address_space *mapping = gl->gl_aspace->i_mapping; | 131 | struct address_space *mapping = gfs2_glock2aspace(gl); |
168 | struct gfs2_sbd *sdp = gl->gl_sbd; | 132 | struct gfs2_sbd *sdp = gl->gl_sbd; |
169 | struct page *page; | 133 | struct page *page; |
170 | struct buffer_head *bh; | 134 | struct buffer_head *bh; |
@@ -344,8 +308,10 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh, | |||
344 | 308 | ||
345 | void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int meta) | 309 | void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int meta) |
346 | { | 310 | { |
347 | struct gfs2_sbd *sdp = GFS2_SB(bh->b_page->mapping->host); | 311 | struct address_space *mapping = bh->b_page->mapping; |
312 | struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping); | ||
348 | struct gfs2_bufdata *bd = bh->b_private; | 313 | struct gfs2_bufdata *bd = bh->b_private; |
314 | |||
349 | if (test_clear_buffer_pinned(bh)) { | 315 | if (test_clear_buffer_pinned(bh)) { |
350 | list_del_init(&bd->bd_le.le_list); | 316 | list_del_init(&bd->bd_le.le_list); |
351 | if (meta) { | 317 | if (meta) { |
diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h index de270c2f9b63..6a1d9ba16411 100644 --- a/fs/gfs2/meta_io.h +++ b/fs/gfs2/meta_io.h | |||
@@ -37,8 +37,16 @@ static inline void gfs2_buffer_copy_tail(struct buffer_head *to_bh, | |||
37 | 0, from_head - to_head); | 37 | 0, from_head - to_head); |
38 | } | 38 | } |
39 | 39 | ||
40 | struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp); | 40 | extern const struct address_space_operations gfs2_meta_aops; |
41 | void gfs2_aspace_put(struct inode *aspace); | 41 | |
42 | static inline struct gfs2_sbd *gfs2_mapping2sbd(struct address_space *mapping) | ||
43 | { | ||
44 | struct inode *inode = mapping->host; | ||
45 | if (mapping->a_ops == &gfs2_meta_aops) | ||
46 | return (((struct gfs2_glock *)mapping) - 1)->gl_sbd; | ||
47 | else | ||
48 | return inode->i_sb->s_fs_info; | ||
49 | } | ||
42 | 50 | ||
43 | void gfs2_meta_sync(struct gfs2_glock *gl); | 51 | void gfs2_meta_sync(struct gfs2_glock *gl); |
44 | 52 | ||
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index a86ed6381566..a054b526dc08 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c | |||
@@ -65,7 +65,6 @@ static void gfs2_tune_init(struct gfs2_tune *gt) | |||
65 | gt->gt_quota_scale_den = 1; | 65 | gt->gt_quota_scale_den = 1; |
66 | gt->gt_new_files_jdata = 0; | 66 | gt->gt_new_files_jdata = 0; |
67 | gt->gt_max_readahead = 1 << 18; | 67 | gt->gt_max_readahead = 1 << 18; |
68 | gt->gt_stall_secs = 600; | ||
69 | gt->gt_complain_secs = 10; | 68 | gt->gt_complain_secs = 10; |
70 | } | 69 | } |
71 | 70 | ||
@@ -1241,10 +1240,9 @@ fail_sb: | |||
1241 | fail_locking: | 1240 | fail_locking: |
1242 | init_locking(sdp, &mount_gh, UNDO); | 1241 | init_locking(sdp, &mount_gh, UNDO); |
1243 | fail_lm: | 1242 | fail_lm: |
1243 | invalidate_inodes(sb); | ||
1244 | gfs2_gl_hash_clear(sdp); | 1244 | gfs2_gl_hash_clear(sdp); |
1245 | gfs2_lm_unmount(sdp); | 1245 | gfs2_lm_unmount(sdp); |
1246 | while (invalidate_inodes(sb)) | ||
1247 | yield(); | ||
1248 | fail_sys: | 1246 | fail_sys: |
1249 | gfs2_sys_fs_del(sdp); | 1247 | gfs2_sys_fs_del(sdp); |
1250 | fail: | 1248 | fail: |
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index b9dd3da22c0a..e5e22629da67 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c | |||
@@ -722,8 +722,7 @@ static int gfs2_write_inode(struct inode *inode, int sync) | |||
722 | int ret = 0; | 722 | int ret = 0; |
723 | 723 | ||
724 | /* Check this is a "normal" inode, etc */ | 724 | /* Check this is a "normal" inode, etc */ |
725 | if (!test_bit(GIF_USER, &ip->i_flags) || | 725 | if (current->flags & PF_MEMALLOC) |
726 | (current->flags & PF_MEMALLOC)) | ||
727 | return 0; | 726 | return 0; |
728 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); | 727 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
729 | if (ret) | 728 | if (ret) |
@@ -860,6 +859,7 @@ restart: | |||
860 | gfs2_clear_rgrpd(sdp); | 859 | gfs2_clear_rgrpd(sdp); |
861 | gfs2_jindex_free(sdp); | 860 | gfs2_jindex_free(sdp); |
862 | /* Take apart glock structures and buffer lists */ | 861 | /* Take apart glock structures and buffer lists */ |
862 | invalidate_inodes(sdp->sd_vfs); | ||
863 | gfs2_gl_hash_clear(sdp); | 863 | gfs2_gl_hash_clear(sdp); |
864 | /* Unmount the locking protocol */ | 864 | /* Unmount the locking protocol */ |
865 | gfs2_lm_unmount(sdp); | 865 | gfs2_lm_unmount(sdp); |
@@ -1194,7 +1194,7 @@ static void gfs2_drop_inode(struct inode *inode) | |||
1194 | { | 1194 | { |
1195 | struct gfs2_inode *ip = GFS2_I(inode); | 1195 | struct gfs2_inode *ip = GFS2_I(inode); |
1196 | 1196 | ||
1197 | if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) { | 1197 | if (inode->i_nlink) { |
1198 | struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl; | 1198 | struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl; |
1199 | if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags)) | 1199 | if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags)) |
1200 | clear_nlink(inode); | 1200 | clear_nlink(inode); |
@@ -1212,18 +1212,12 @@ static void gfs2_clear_inode(struct inode *inode) | |||
1212 | { | 1212 | { |
1213 | struct gfs2_inode *ip = GFS2_I(inode); | 1213 | struct gfs2_inode *ip = GFS2_I(inode); |
1214 | 1214 | ||
1215 | /* This tells us its a "real" inode and not one which only | 1215 | ip->i_gl->gl_object = NULL; |
1216 | * serves to contain an address space (see rgrp.c, meta_io.c) | 1216 | gfs2_glock_put(ip->i_gl); |
1217 | * which therefore doesn't have its own glocks. | 1217 | ip->i_gl = NULL; |
1218 | */ | 1218 | if (ip->i_iopen_gh.gh_gl) { |
1219 | if (test_bit(GIF_USER, &ip->i_flags)) { | 1219 | ip->i_iopen_gh.gh_gl->gl_object = NULL; |
1220 | ip->i_gl->gl_object = NULL; | 1220 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); |
1221 | gfs2_glock_put(ip->i_gl); | ||
1222 | ip->i_gl = NULL; | ||
1223 | if (ip->i_iopen_gh.gh_gl) { | ||
1224 | ip->i_iopen_gh.gh_gl->gl_object = NULL; | ||
1225 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); | ||
1226 | } | ||
1227 | } | 1221 | } |
1228 | } | 1222 | } |
1229 | 1223 | ||
@@ -1358,9 +1352,6 @@ static void gfs2_delete_inode(struct inode *inode) | |||
1358 | struct gfs2_holder gh; | 1352 | struct gfs2_holder gh; |
1359 | int error; | 1353 | int error; |
1360 | 1354 | ||
1361 | if (!test_bit(GIF_USER, &ip->i_flags)) | ||
1362 | goto out; | ||
1363 | |||
1364 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); | 1355 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
1365 | if (unlikely(error)) { | 1356 | if (unlikely(error)) { |
1366 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); | 1357 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); |
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index 0dc34621f6a6..a0db1c94317d 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c | |||
@@ -478,7 +478,6 @@ TUNE_ATTR(complain_secs, 0); | |||
478 | TUNE_ATTR(statfs_slow, 0); | 478 | TUNE_ATTR(statfs_slow, 0); |
479 | TUNE_ATTR(new_files_jdata, 0); | 479 | TUNE_ATTR(new_files_jdata, 0); |
480 | TUNE_ATTR(quota_simul_sync, 1); | 480 | TUNE_ATTR(quota_simul_sync, 1); |
481 | TUNE_ATTR(stall_secs, 1); | ||
482 | TUNE_ATTR(statfs_quantum, 1); | 481 | TUNE_ATTR(statfs_quantum, 1); |
483 | TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); | 482 | TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); |
484 | 483 | ||
@@ -491,7 +490,6 @@ static struct attribute *tune_attrs[] = { | |||
491 | &tune_attr_complain_secs.attr, | 490 | &tune_attr_complain_secs.attr, |
492 | &tune_attr_statfs_slow.attr, | 491 | &tune_attr_statfs_slow.attr, |
493 | &tune_attr_quota_simul_sync.attr, | 492 | &tune_attr_quota_simul_sync.attr, |
494 | &tune_attr_stall_secs.attr, | ||
495 | &tune_attr_statfs_quantum.attr, | 493 | &tune_attr_statfs_quantum.attr, |
496 | &tune_attr_quota_scale.attr, | 494 | &tune_attr_quota_scale.attr, |
497 | &tune_attr_new_files_jdata.attr, | 495 | &tune_attr_new_files_jdata.attr, |
diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index f6a7efa34eb9..226f2bfbf16a 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "util.h" | 21 | #include "util.h" |
22 | 22 | ||
23 | struct kmem_cache *gfs2_glock_cachep __read_mostly; | 23 | struct kmem_cache *gfs2_glock_cachep __read_mostly; |
24 | struct kmem_cache *gfs2_glock_aspace_cachep __read_mostly; | ||
24 | struct kmem_cache *gfs2_inode_cachep __read_mostly; | 25 | struct kmem_cache *gfs2_inode_cachep __read_mostly; |
25 | struct kmem_cache *gfs2_bufdata_cachep __read_mostly; | 26 | struct kmem_cache *gfs2_bufdata_cachep __read_mostly; |
26 | struct kmem_cache *gfs2_rgrpd_cachep __read_mostly; | 27 | struct kmem_cache *gfs2_rgrpd_cachep __read_mostly; |
diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index 33e96b0ce9ab..b432e04600de 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h | |||
@@ -145,6 +145,7 @@ gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__); | |||
145 | 145 | ||
146 | 146 | ||
147 | extern struct kmem_cache *gfs2_glock_cachep; | 147 | extern struct kmem_cache *gfs2_glock_cachep; |
148 | extern struct kmem_cache *gfs2_glock_aspace_cachep; | ||
148 | extern struct kmem_cache *gfs2_inode_cachep; | 149 | extern struct kmem_cache *gfs2_inode_cachep; |
149 | extern struct kmem_cache *gfs2_bufdata_cachep; | 150 | extern struct kmem_cache *gfs2_bufdata_cachep; |
150 | extern struct kmem_cache *gfs2_rgrpd_cachep; | 151 | extern struct kmem_cache *gfs2_rgrpd_cachep; |
diff --git a/fs/nfs/iostat.h b/fs/nfs/iostat.h index 46d779abafd3..1d8d5c813b01 100644 --- a/fs/nfs/iostat.h +++ b/fs/nfs/iostat.h | |||
@@ -57,12 +57,12 @@ static inline void nfs_add_fscache_stats(struct inode *inode, | |||
57 | } | 57 | } |
58 | #endif | 58 | #endif |
59 | 59 | ||
60 | static inline struct nfs_iostats *nfs_alloc_iostats(void) | 60 | static inline struct nfs_iostats __percpu *nfs_alloc_iostats(void) |
61 | { | 61 | { |
62 | return alloc_percpu(struct nfs_iostats); | 62 | return alloc_percpu(struct nfs_iostats); |
63 | } | 63 | } |
64 | 64 | ||
65 | static inline void nfs_free_iostats(struct nfs_iostats *stats) | 65 | static inline void nfs_free_iostats(struct nfs_iostats __percpu *stats) |
66 | { | 66 | { |
67 | if (stats != NULL) | 67 | if (stats != NULL) |
68 | free_percpu(stats); | 68 | free_percpu(stats); |
diff --git a/fs/nilfs2/dat.c b/fs/nilfs2/dat.c index 187dd07ba86c..9d1e5de91afb 100644 --- a/fs/nilfs2/dat.c +++ b/fs/nilfs2/dat.c | |||
@@ -388,8 +388,7 @@ int nilfs_dat_translate(struct inode *dat, __u64 vblocknr, sector_t *blocknrp) | |||
388 | ret = -ENOENT; | 388 | ret = -ENOENT; |
389 | goto out; | 389 | goto out; |
390 | } | 390 | } |
391 | if (blocknrp != NULL) | 391 | *blocknrp = blocknr; |
392 | *blocknrp = blocknr; | ||
393 | 392 | ||
394 | out: | 393 | out: |
395 | kunmap_atomic(kaddr, KM_USER0); | 394 | kunmap_atomic(kaddr, KM_USER0); |
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c index d6b2b83de363..313d0a21da48 100644 --- a/fs/nilfs2/ioctl.c +++ b/fs/nilfs2/ioctl.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/capability.h> /* capable() */ | 26 | #include <linux/capability.h> /* capable() */ |
27 | #include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */ | 27 | #include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */ |
28 | #include <linux/vmalloc.h> | 28 | #include <linux/vmalloc.h> |
29 | #include <linux/mount.h> /* mnt_want_write(), mnt_drop_write() */ | ||
29 | #include <linux/nilfs2_fs.h> | 30 | #include <linux/nilfs2_fs.h> |
30 | #include "nilfs.h" | 31 | #include "nilfs.h" |
31 | #include "segment.h" | 32 | #include "segment.h" |
@@ -107,20 +108,28 @@ static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp, | |||
107 | 108 | ||
108 | if (!capable(CAP_SYS_ADMIN)) | 109 | if (!capable(CAP_SYS_ADMIN)) |
109 | return -EPERM; | 110 | return -EPERM; |
111 | |||
112 | ret = mnt_want_write(filp->f_path.mnt); | ||
113 | if (ret) | ||
114 | return ret; | ||
115 | |||
116 | ret = -EFAULT; | ||
110 | if (copy_from_user(&cpmode, argp, sizeof(cpmode))) | 117 | if (copy_from_user(&cpmode, argp, sizeof(cpmode))) |
111 | return -EFAULT; | 118 | goto out; |
112 | 119 | ||
113 | mutex_lock(&nilfs->ns_mount_mutex); | 120 | mutex_lock(&nilfs->ns_mount_mutex); |
121 | |||
114 | nilfs_transaction_begin(inode->i_sb, &ti, 0); | 122 | nilfs_transaction_begin(inode->i_sb, &ti, 0); |
115 | ret = nilfs_cpfile_change_cpmode( | 123 | ret = nilfs_cpfile_change_cpmode( |
116 | cpfile, cpmode.cm_cno, cpmode.cm_mode); | 124 | cpfile, cpmode.cm_cno, cpmode.cm_mode); |
117 | if (unlikely(ret < 0)) { | 125 | if (unlikely(ret < 0)) |
118 | nilfs_transaction_abort(inode->i_sb); | 126 | nilfs_transaction_abort(inode->i_sb); |
119 | mutex_unlock(&nilfs->ns_mount_mutex); | 127 | else |
120 | return ret; | 128 | nilfs_transaction_commit(inode->i_sb); /* never fails */ |
121 | } | 129 | |
122 | nilfs_transaction_commit(inode->i_sb); /* never fails */ | ||
123 | mutex_unlock(&nilfs->ns_mount_mutex); | 130 | mutex_unlock(&nilfs->ns_mount_mutex); |
131 | out: | ||
132 | mnt_drop_write(filp->f_path.mnt); | ||
124 | return ret; | 133 | return ret; |
125 | } | 134 | } |
126 | 135 | ||
@@ -135,16 +144,23 @@ nilfs_ioctl_delete_checkpoint(struct inode *inode, struct file *filp, | |||
135 | 144 | ||
136 | if (!capable(CAP_SYS_ADMIN)) | 145 | if (!capable(CAP_SYS_ADMIN)) |
137 | return -EPERM; | 146 | return -EPERM; |
147 | |||
148 | ret = mnt_want_write(filp->f_path.mnt); | ||
149 | if (ret) | ||
150 | return ret; | ||
151 | |||
152 | ret = -EFAULT; | ||
138 | if (copy_from_user(&cno, argp, sizeof(cno))) | 153 | if (copy_from_user(&cno, argp, sizeof(cno))) |
139 | return -EFAULT; | 154 | goto out; |
140 | 155 | ||
141 | nilfs_transaction_begin(inode->i_sb, &ti, 0); | 156 | nilfs_transaction_begin(inode->i_sb, &ti, 0); |
142 | ret = nilfs_cpfile_delete_checkpoint(cpfile, cno); | 157 | ret = nilfs_cpfile_delete_checkpoint(cpfile, cno); |
143 | if (unlikely(ret < 0)) { | 158 | if (unlikely(ret < 0)) |
144 | nilfs_transaction_abort(inode->i_sb); | 159 | nilfs_transaction_abort(inode->i_sb); |
145 | return ret; | 160 | else |
146 | } | 161 | nilfs_transaction_commit(inode->i_sb); /* never fails */ |
147 | nilfs_transaction_commit(inode->i_sb); /* never fails */ | 162 | out: |
163 | mnt_drop_write(filp->f_path.mnt); | ||
148 | return ret; | 164 | return ret; |
149 | } | 165 | } |
150 | 166 | ||
@@ -496,12 +512,19 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp, | |||
496 | if (!capable(CAP_SYS_ADMIN)) | 512 | if (!capable(CAP_SYS_ADMIN)) |
497 | return -EPERM; | 513 | return -EPERM; |
498 | 514 | ||
515 | ret = mnt_want_write(filp->f_path.mnt); | ||
516 | if (ret) | ||
517 | return ret; | ||
518 | |||
519 | ret = -EFAULT; | ||
499 | if (copy_from_user(argv, argp, sizeof(argv))) | 520 | if (copy_from_user(argv, argp, sizeof(argv))) |
500 | return -EFAULT; | 521 | goto out; |
501 | 522 | ||
523 | ret = -EINVAL; | ||
502 | nsegs = argv[4].v_nmembs; | 524 | nsegs = argv[4].v_nmembs; |
503 | if (argv[4].v_size != argsz[4]) | 525 | if (argv[4].v_size != argsz[4]) |
504 | return -EINVAL; | 526 | goto out; |
527 | |||
505 | /* | 528 | /* |
506 | * argv[4] points to segment numbers this ioctl cleans. We | 529 | * argv[4] points to segment numbers this ioctl cleans. We |
507 | * use kmalloc() for its buffer because memory used for the | 530 | * use kmalloc() for its buffer because memory used for the |
@@ -509,9 +532,10 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp, | |||
509 | */ | 532 | */ |
510 | kbufs[4] = memdup_user((void __user *)(unsigned long)argv[4].v_base, | 533 | kbufs[4] = memdup_user((void __user *)(unsigned long)argv[4].v_base, |
511 | nsegs * sizeof(__u64)); | 534 | nsegs * sizeof(__u64)); |
512 | if (IS_ERR(kbufs[4])) | 535 | if (IS_ERR(kbufs[4])) { |
513 | return PTR_ERR(kbufs[4]); | 536 | ret = PTR_ERR(kbufs[4]); |
514 | 537 | goto out; | |
538 | } | ||
515 | nilfs = NILFS_SB(inode->i_sb)->s_nilfs; | 539 | nilfs = NILFS_SB(inode->i_sb)->s_nilfs; |
516 | 540 | ||
517 | for (n = 0; n < 4; n++) { | 541 | for (n = 0; n < 4; n++) { |
@@ -563,10 +587,12 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp, | |||
563 | nilfs_remove_all_gcinode(nilfs); | 587 | nilfs_remove_all_gcinode(nilfs); |
564 | clear_nilfs_gc_running(nilfs); | 588 | clear_nilfs_gc_running(nilfs); |
565 | 589 | ||
566 | out_free: | 590 | out_free: |
567 | while (--n >= 0) | 591 | while (--n >= 0) |
568 | vfree(kbufs[n]); | 592 | vfree(kbufs[n]); |
569 | kfree(kbufs[4]); | 593 | kfree(kbufs[4]); |
594 | out: | ||
595 | mnt_drop_write(filp->f_path.mnt); | ||
570 | return ret; | 596 | return ret; |
571 | } | 597 | } |
572 | 598 | ||
@@ -575,13 +601,17 @@ static int nilfs_ioctl_sync(struct inode *inode, struct file *filp, | |||
575 | { | 601 | { |
576 | __u64 cno; | 602 | __u64 cno; |
577 | int ret; | 603 | int ret; |
604 | struct the_nilfs *nilfs; | ||
578 | 605 | ||
579 | ret = nilfs_construct_segment(inode->i_sb); | 606 | ret = nilfs_construct_segment(inode->i_sb); |
580 | if (ret < 0) | 607 | if (ret < 0) |
581 | return ret; | 608 | return ret; |
582 | 609 | ||
583 | if (argp != NULL) { | 610 | if (argp != NULL) { |
584 | cno = NILFS_SB(inode->i_sb)->s_nilfs->ns_cno - 1; | 611 | nilfs = NILFS_SB(inode->i_sb)->s_nilfs; |
612 | down_read(&nilfs->ns_segctor_sem); | ||
613 | cno = nilfs->ns_cno - 1; | ||
614 | up_read(&nilfs->ns_segctor_sem); | ||
585 | if (copy_to_user(argp, &cno, sizeof(cno))) | 615 | if (copy_to_user(argp, &cno, sizeof(cno))) |
586 | return -EFAULT; | 616 | return -EFAULT; |
587 | } | 617 | } |
diff --git a/fs/nilfs2/recovery.c b/fs/nilfs2/recovery.c index c9c96c7825dc..017bedc761a0 100644 --- a/fs/nilfs2/recovery.c +++ b/fs/nilfs2/recovery.c | |||
@@ -39,7 +39,6 @@ enum { | |||
39 | NILFS_SEG_FAIL_IO, | 39 | NILFS_SEG_FAIL_IO, |
40 | NILFS_SEG_FAIL_MAGIC, | 40 | NILFS_SEG_FAIL_MAGIC, |
41 | NILFS_SEG_FAIL_SEQ, | 41 | NILFS_SEG_FAIL_SEQ, |
42 | NILFS_SEG_FAIL_CHECKSUM_SEGSUM, | ||
43 | NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT, | 42 | NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT, |
44 | NILFS_SEG_FAIL_CHECKSUM_FULL, | 43 | NILFS_SEG_FAIL_CHECKSUM_FULL, |
45 | NILFS_SEG_FAIL_CONSISTENCY, | 44 | NILFS_SEG_FAIL_CONSISTENCY, |
@@ -71,10 +70,6 @@ static int nilfs_warn_segment_error(int err) | |||
71 | printk(KERN_WARNING | 70 | printk(KERN_WARNING |
72 | "NILFS warning: Sequence number mismatch\n"); | 71 | "NILFS warning: Sequence number mismatch\n"); |
73 | break; | 72 | break; |
74 | case NILFS_SEG_FAIL_CHECKSUM_SEGSUM: | ||
75 | printk(KERN_WARNING | ||
76 | "NILFS warning: Checksum error in segment summary\n"); | ||
77 | break; | ||
78 | case NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT: | 73 | case NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT: |
79 | printk(KERN_WARNING | 74 | printk(KERN_WARNING |
80 | "NILFS warning: Checksum error in super root\n"); | 75 | "NILFS warning: Checksum error in super root\n"); |
@@ -206,19 +201,15 @@ int nilfs_read_super_root_block(struct super_block *sb, sector_t sr_block, | |||
206 | * @pseg_start: start disk block number of partial segment | 201 | * @pseg_start: start disk block number of partial segment |
207 | * @seg_seq: sequence number requested | 202 | * @seg_seq: sequence number requested |
208 | * @ssi: pointer to nilfs_segsum_info struct to store information | 203 | * @ssi: pointer to nilfs_segsum_info struct to store information |
209 | * @full_check: full check flag | ||
210 | * (0: only checks segment summary CRC, 1: data CRC) | ||
211 | */ | 204 | */ |
212 | static int | 205 | static int |
213 | load_segment_summary(struct nilfs_sb_info *sbi, sector_t pseg_start, | 206 | load_segment_summary(struct nilfs_sb_info *sbi, sector_t pseg_start, |
214 | u64 seg_seq, struct nilfs_segsum_info *ssi, | 207 | u64 seg_seq, struct nilfs_segsum_info *ssi) |
215 | int full_check) | ||
216 | { | 208 | { |
217 | struct buffer_head *bh_sum; | 209 | struct buffer_head *bh_sum; |
218 | struct nilfs_segment_summary *sum; | 210 | struct nilfs_segment_summary *sum; |
219 | unsigned long offset, nblock; | 211 | unsigned long nblock; |
220 | u64 check_bytes; | 212 | u32 crc; |
221 | u32 crc, crc_sum; | ||
222 | int ret = NILFS_SEG_FAIL_IO; | 213 | int ret = NILFS_SEG_FAIL_IO; |
223 | 214 | ||
224 | bh_sum = sb_bread(sbi->s_super, pseg_start); | 215 | bh_sum = sb_bread(sbi->s_super, pseg_start); |
@@ -237,34 +228,24 @@ load_segment_summary(struct nilfs_sb_info *sbi, sector_t pseg_start, | |||
237 | ret = NILFS_SEG_FAIL_SEQ; | 228 | ret = NILFS_SEG_FAIL_SEQ; |
238 | goto failed; | 229 | goto failed; |
239 | } | 230 | } |
240 | if (full_check) { | ||
241 | offset = sizeof(sum->ss_datasum); | ||
242 | check_bytes = | ||
243 | ((u64)ssi->nblocks << sbi->s_super->s_blocksize_bits); | ||
244 | nblock = ssi->nblocks; | ||
245 | crc_sum = le32_to_cpu(sum->ss_datasum); | ||
246 | ret = NILFS_SEG_FAIL_CHECKSUM_FULL; | ||
247 | } else { /* only checks segment summary */ | ||
248 | offset = sizeof(sum->ss_datasum) + sizeof(sum->ss_sumsum); | ||
249 | check_bytes = ssi->sumbytes; | ||
250 | nblock = ssi->nsumblk; | ||
251 | crc_sum = le32_to_cpu(sum->ss_sumsum); | ||
252 | ret = NILFS_SEG_FAIL_CHECKSUM_SEGSUM; | ||
253 | } | ||
254 | 231 | ||
232 | nblock = ssi->nblocks; | ||
255 | if (unlikely(nblock == 0 || | 233 | if (unlikely(nblock == 0 || |
256 | nblock > sbi->s_nilfs->ns_blocks_per_segment)) { | 234 | nblock > sbi->s_nilfs->ns_blocks_per_segment)) { |
257 | /* This limits the number of blocks read in the CRC check */ | 235 | /* This limits the number of blocks read in the CRC check */ |
258 | ret = NILFS_SEG_FAIL_CONSISTENCY; | 236 | ret = NILFS_SEG_FAIL_CONSISTENCY; |
259 | goto failed; | 237 | goto failed; |
260 | } | 238 | } |
261 | if (calc_crc_cont(sbi, bh_sum, &crc, offset, check_bytes, | 239 | if (calc_crc_cont(sbi, bh_sum, &crc, sizeof(sum->ss_datasum), |
240 | ((u64)nblock << sbi->s_super->s_blocksize_bits), | ||
262 | pseg_start, nblock)) { | 241 | pseg_start, nblock)) { |
263 | ret = NILFS_SEG_FAIL_IO; | 242 | ret = NILFS_SEG_FAIL_IO; |
264 | goto failed; | 243 | goto failed; |
265 | } | 244 | } |
266 | if (crc == crc_sum) | 245 | if (crc == le32_to_cpu(sum->ss_datasum)) |
267 | ret = 0; | 246 | ret = 0; |
247 | else | ||
248 | ret = NILFS_SEG_FAIL_CHECKSUM_FULL; | ||
268 | failed: | 249 | failed: |
269 | brelse(bh_sum); | 250 | brelse(bh_sum); |
270 | out: | 251 | out: |
@@ -598,7 +579,7 @@ static int nilfs_do_roll_forward(struct the_nilfs *nilfs, | |||
598 | 579 | ||
599 | while (segnum != ri->ri_segnum || pseg_start <= ri->ri_pseg_start) { | 580 | while (segnum != ri->ri_segnum || pseg_start <= ri->ri_pseg_start) { |
600 | 581 | ||
601 | ret = load_segment_summary(sbi, pseg_start, seg_seq, &ssi, 1); | 582 | ret = load_segment_summary(sbi, pseg_start, seg_seq, &ssi); |
602 | if (ret) { | 583 | if (ret) { |
603 | if (ret == NILFS_SEG_FAIL_IO) { | 584 | if (ret == NILFS_SEG_FAIL_IO) { |
604 | err = -EIO; | 585 | err = -EIO; |
@@ -821,7 +802,7 @@ int nilfs_search_super_root(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi, | |||
821 | 802 | ||
822 | for (;;) { | 803 | for (;;) { |
823 | /* Load segment summary */ | 804 | /* Load segment summary */ |
824 | ret = load_segment_summary(sbi, pseg_start, seg_seq, &ssi, 1); | 805 | ret = load_segment_summary(sbi, pseg_start, seg_seq, &ssi); |
825 | if (ret) { | 806 | if (ret) { |
826 | if (ret == NILFS_SEG_FAIL_IO) | 807 | if (ret == NILFS_SEG_FAIL_IO) |
827 | goto failed; | 808 | goto failed; |
diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c index 645c78656aa0..ab56fe44e377 100644 --- a/fs/nilfs2/segbuf.c +++ b/fs/nilfs2/segbuf.c | |||
@@ -40,6 +40,11 @@ struct nilfs_write_info { | |||
40 | }; | 40 | }; |
41 | 41 | ||
42 | 42 | ||
43 | static int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, | ||
44 | struct the_nilfs *nilfs); | ||
45 | static int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf); | ||
46 | |||
47 | |||
43 | static struct kmem_cache *nilfs_segbuf_cachep; | 48 | static struct kmem_cache *nilfs_segbuf_cachep; |
44 | 49 | ||
45 | static void nilfs_segbuf_init_once(void *obj) | 50 | static void nilfs_segbuf_init_once(void *obj) |
@@ -302,6 +307,19 @@ void nilfs_truncate_logs(struct list_head *logs, | |||
302 | } | 307 | } |
303 | } | 308 | } |
304 | 309 | ||
310 | int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs) | ||
311 | { | ||
312 | struct nilfs_segment_buffer *segbuf; | ||
313 | int ret = 0; | ||
314 | |||
315 | list_for_each_entry(segbuf, logs, sb_list) { | ||
316 | ret = nilfs_segbuf_write(segbuf, nilfs); | ||
317 | if (ret) | ||
318 | break; | ||
319 | } | ||
320 | return ret; | ||
321 | } | ||
322 | |||
305 | int nilfs_wait_on_logs(struct list_head *logs) | 323 | int nilfs_wait_on_logs(struct list_head *logs) |
306 | { | 324 | { |
307 | struct nilfs_segment_buffer *segbuf; | 325 | struct nilfs_segment_buffer *segbuf; |
diff --git a/fs/nilfs2/segbuf.h b/fs/nilfs2/segbuf.h index 6af1630fb401..94dfd3517bc0 100644 --- a/fs/nilfs2/segbuf.h +++ b/fs/nilfs2/segbuf.h | |||
@@ -166,13 +166,10 @@ nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf, | |||
166 | segbuf->sb_sum.nfileblk++; | 166 | segbuf->sb_sum.nfileblk++; |
167 | } | 167 | } |
168 | 168 | ||
169 | int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, | ||
170 | struct the_nilfs *nilfs); | ||
171 | int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf); | ||
172 | |||
173 | void nilfs_clear_logs(struct list_head *logs); | 169 | void nilfs_clear_logs(struct list_head *logs); |
174 | void nilfs_truncate_logs(struct list_head *logs, | 170 | void nilfs_truncate_logs(struct list_head *logs, |
175 | struct nilfs_segment_buffer *last); | 171 | struct nilfs_segment_buffer *last); |
172 | int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs); | ||
176 | int nilfs_wait_on_logs(struct list_head *logs); | 173 | int nilfs_wait_on_logs(struct list_head *logs); |
177 | 174 | ||
178 | static inline void nilfs_destroy_logs(struct list_head *logs) | 175 | static inline void nilfs_destroy_logs(struct list_head *logs) |
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index 105b508b47a8..ada2f1b947a3 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c | |||
@@ -1764,14 +1764,9 @@ static int nilfs_segctor_prepare_write(struct nilfs_sc_info *sci, | |||
1764 | static int nilfs_segctor_write(struct nilfs_sc_info *sci, | 1764 | static int nilfs_segctor_write(struct nilfs_sc_info *sci, |
1765 | struct the_nilfs *nilfs) | 1765 | struct the_nilfs *nilfs) |
1766 | { | 1766 | { |
1767 | struct nilfs_segment_buffer *segbuf; | 1767 | int ret; |
1768 | int ret = 0; | ||
1769 | 1768 | ||
1770 | list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) { | 1769 | ret = nilfs_write_logs(&sci->sc_segbufs, nilfs); |
1771 | ret = nilfs_segbuf_write(segbuf, nilfs); | ||
1772 | if (ret) | ||
1773 | break; | ||
1774 | } | ||
1775 | list_splice_tail_init(&sci->sc_segbufs, &sci->sc_write_logs); | 1770 | list_splice_tail_init(&sci->sc_segbufs, &sci->sc_write_logs); |
1776 | return ret; | 1771 | return ret; |
1777 | } | 1772 | } |
@@ -1937,8 +1932,7 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) | |||
1937 | { | 1932 | { |
1938 | struct nilfs_segment_buffer *segbuf; | 1933 | struct nilfs_segment_buffer *segbuf; |
1939 | struct page *bd_page = NULL, *fs_page = NULL; | 1934 | struct page *bd_page = NULL, *fs_page = NULL; |
1940 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 1935 | struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs; |
1941 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
1942 | int update_sr = (sci->sc_super_root != NULL); | 1936 | int update_sr = (sci->sc_super_root != NULL); |
1943 | 1937 | ||
1944 | list_for_each_entry(segbuf, &sci->sc_write_logs, sb_list) { | 1938 | list_for_each_entry(segbuf, &sci->sc_write_logs, sb_list) { |
@@ -2020,7 +2014,7 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) | |||
2020 | if (update_sr) { | 2014 | if (update_sr) { |
2021 | nilfs_set_last_segment(nilfs, segbuf->sb_pseg_start, | 2015 | nilfs_set_last_segment(nilfs, segbuf->sb_pseg_start, |
2022 | segbuf->sb_sum.seg_seq, nilfs->ns_cno++); | 2016 | segbuf->sb_sum.seg_seq, nilfs->ns_cno++); |
2023 | sbi->s_super->s_dirt = 1; | 2017 | set_nilfs_sb_dirty(nilfs); |
2024 | 2018 | ||
2025 | clear_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags); | 2019 | clear_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags); |
2026 | clear_bit(NILFS_SC_DIRTY, &sci->sc_flags); | 2020 | clear_bit(NILFS_SC_DIRTY, &sci->sc_flags); |
@@ -2425,43 +2419,43 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode, | |||
2425 | return err; | 2419 | return err; |
2426 | } | 2420 | } |
2427 | 2421 | ||
2428 | struct nilfs_segctor_req { | ||
2429 | int mode; | ||
2430 | __u32 seq_accepted; | ||
2431 | int sc_err; /* construction failure */ | ||
2432 | int sb_err; /* super block writeback failure */ | ||
2433 | }; | ||
2434 | |||
2435 | #define FLUSH_FILE_BIT (0x1) /* data file only */ | 2422 | #define FLUSH_FILE_BIT (0x1) /* data file only */ |
2436 | #define FLUSH_DAT_BIT (1 << NILFS_DAT_INO) /* DAT only */ | 2423 | #define FLUSH_DAT_BIT (1 << NILFS_DAT_INO) /* DAT only */ |
2437 | 2424 | ||
2438 | static void nilfs_segctor_accept(struct nilfs_sc_info *sci, | 2425 | /** |
2439 | struct nilfs_segctor_req *req) | 2426 | * nilfs_segctor_accept - record accepted sequence count of log-write requests |
2427 | * @sci: segment constructor object | ||
2428 | */ | ||
2429 | static void nilfs_segctor_accept(struct nilfs_sc_info *sci) | ||
2440 | { | 2430 | { |
2441 | req->sc_err = req->sb_err = 0; | ||
2442 | spin_lock(&sci->sc_state_lock); | 2431 | spin_lock(&sci->sc_state_lock); |
2443 | req->seq_accepted = sci->sc_seq_request; | 2432 | sci->sc_seq_accepted = sci->sc_seq_request; |
2444 | spin_unlock(&sci->sc_state_lock); | 2433 | spin_unlock(&sci->sc_state_lock); |
2445 | 2434 | ||
2446 | if (sci->sc_timer) | 2435 | if (sci->sc_timer) |
2447 | del_timer_sync(sci->sc_timer); | 2436 | del_timer_sync(sci->sc_timer); |
2448 | } | 2437 | } |
2449 | 2438 | ||
2450 | static void nilfs_segctor_notify(struct nilfs_sc_info *sci, | 2439 | /** |
2451 | struct nilfs_segctor_req *req) | 2440 | * nilfs_segctor_notify - notify the result of request to caller threads |
2441 | * @sci: segment constructor object | ||
2442 | * @mode: mode of log forming | ||
2443 | * @err: error code to be notified | ||
2444 | */ | ||
2445 | static void nilfs_segctor_notify(struct nilfs_sc_info *sci, int mode, int err) | ||
2452 | { | 2446 | { |
2453 | /* Clear requests (even when the construction failed) */ | 2447 | /* Clear requests (even when the construction failed) */ |
2454 | spin_lock(&sci->sc_state_lock); | 2448 | spin_lock(&sci->sc_state_lock); |
2455 | 2449 | ||
2456 | if (req->mode == SC_LSEG_SR) { | 2450 | if (mode == SC_LSEG_SR) { |
2457 | sci->sc_state &= ~NILFS_SEGCTOR_COMMIT; | 2451 | sci->sc_state &= ~NILFS_SEGCTOR_COMMIT; |
2458 | sci->sc_seq_done = req->seq_accepted; | 2452 | sci->sc_seq_done = sci->sc_seq_accepted; |
2459 | nilfs_segctor_wakeup(sci, req->sc_err ? : req->sb_err); | 2453 | nilfs_segctor_wakeup(sci, err); |
2460 | sci->sc_flush_request = 0; | 2454 | sci->sc_flush_request = 0; |
2461 | } else { | 2455 | } else { |
2462 | if (req->mode == SC_FLUSH_FILE) | 2456 | if (mode == SC_FLUSH_FILE) |
2463 | sci->sc_flush_request &= ~FLUSH_FILE_BIT; | 2457 | sci->sc_flush_request &= ~FLUSH_FILE_BIT; |
2464 | else if (req->mode == SC_FLUSH_DAT) | 2458 | else if (mode == SC_FLUSH_DAT) |
2465 | sci->sc_flush_request &= ~FLUSH_DAT_BIT; | 2459 | sci->sc_flush_request &= ~FLUSH_DAT_BIT; |
2466 | 2460 | ||
2467 | /* re-enable timer if checkpoint creation was not done */ | 2461 | /* re-enable timer if checkpoint creation was not done */ |
@@ -2472,30 +2466,37 @@ static void nilfs_segctor_notify(struct nilfs_sc_info *sci, | |||
2472 | spin_unlock(&sci->sc_state_lock); | 2466 | spin_unlock(&sci->sc_state_lock); |
2473 | } | 2467 | } |
2474 | 2468 | ||
2475 | static int nilfs_segctor_construct(struct nilfs_sc_info *sci, | 2469 | /** |
2476 | struct nilfs_segctor_req *req) | 2470 | * nilfs_segctor_construct - form logs and write them to disk |
2471 | * @sci: segment constructor object | ||
2472 | * @mode: mode of log forming | ||
2473 | */ | ||
2474 | static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode) | ||
2477 | { | 2475 | { |
2478 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 2476 | struct nilfs_sb_info *sbi = sci->sc_sbi; |
2479 | struct the_nilfs *nilfs = sbi->s_nilfs; | 2477 | struct the_nilfs *nilfs = sbi->s_nilfs; |
2480 | int err = 0; | 2478 | int err = 0; |
2481 | 2479 | ||
2480 | nilfs_segctor_accept(sci); | ||
2481 | |||
2482 | if (nilfs_discontinued(nilfs)) | 2482 | if (nilfs_discontinued(nilfs)) |
2483 | req->mode = SC_LSEG_SR; | 2483 | mode = SC_LSEG_SR; |
2484 | if (!nilfs_segctor_confirm(sci)) { | 2484 | if (!nilfs_segctor_confirm(sci)) |
2485 | err = nilfs_segctor_do_construct(sci, req->mode); | 2485 | err = nilfs_segctor_do_construct(sci, mode); |
2486 | req->sc_err = err; | 2486 | |
2487 | } | ||
2488 | if (likely(!err)) { | 2487 | if (likely(!err)) { |
2489 | if (req->mode != SC_FLUSH_DAT) | 2488 | if (mode != SC_FLUSH_DAT) |
2490 | atomic_set(&nilfs->ns_ndirtyblks, 0); | 2489 | atomic_set(&nilfs->ns_ndirtyblks, 0); |
2491 | if (test_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags) && | 2490 | if (test_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags) && |
2492 | nilfs_discontinued(nilfs)) { | 2491 | nilfs_discontinued(nilfs)) { |
2493 | down_write(&nilfs->ns_sem); | 2492 | down_write(&nilfs->ns_sem); |
2494 | req->sb_err = nilfs_commit_super(sbi, | 2493 | err = nilfs_commit_super( |
2495 | nilfs_altsb_need_update(nilfs)); | 2494 | sbi, nilfs_altsb_need_update(nilfs)); |
2496 | up_write(&nilfs->ns_sem); | 2495 | up_write(&nilfs->ns_sem); |
2497 | } | 2496 | } |
2498 | } | 2497 | } |
2498 | |||
2499 | nilfs_segctor_notify(sci, mode, err); | ||
2499 | return err; | 2500 | return err; |
2500 | } | 2501 | } |
2501 | 2502 | ||
@@ -2526,7 +2527,6 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, | |||
2526 | struct nilfs_sc_info *sci = NILFS_SC(sbi); | 2527 | struct nilfs_sc_info *sci = NILFS_SC(sbi); |
2527 | struct the_nilfs *nilfs = sbi->s_nilfs; | 2528 | struct the_nilfs *nilfs = sbi->s_nilfs; |
2528 | struct nilfs_transaction_info ti; | 2529 | struct nilfs_transaction_info ti; |
2529 | struct nilfs_segctor_req req = { .mode = SC_LSEG_SR }; | ||
2530 | int err; | 2530 | int err; |
2531 | 2531 | ||
2532 | if (unlikely(!sci)) | 2532 | if (unlikely(!sci)) |
@@ -2547,10 +2547,8 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, | |||
2547 | list_splice_tail_init(&nilfs->ns_gc_inodes, &sci->sc_gc_inodes); | 2547 | list_splice_tail_init(&nilfs->ns_gc_inodes, &sci->sc_gc_inodes); |
2548 | 2548 | ||
2549 | for (;;) { | 2549 | for (;;) { |
2550 | nilfs_segctor_accept(sci, &req); | 2550 | err = nilfs_segctor_construct(sci, SC_LSEG_SR); |
2551 | err = nilfs_segctor_construct(sci, &req); | ||
2552 | nilfs_remove_written_gcinodes(nilfs, &sci->sc_gc_inodes); | 2551 | nilfs_remove_written_gcinodes(nilfs, &sci->sc_gc_inodes); |
2553 | nilfs_segctor_notify(sci, &req); | ||
2554 | 2552 | ||
2555 | if (likely(!err)) | 2553 | if (likely(!err)) |
2556 | break; | 2554 | break; |
@@ -2560,6 +2558,16 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, | |||
2560 | set_current_state(TASK_INTERRUPTIBLE); | 2558 | set_current_state(TASK_INTERRUPTIBLE); |
2561 | schedule_timeout(sci->sc_interval); | 2559 | schedule_timeout(sci->sc_interval); |
2562 | } | 2560 | } |
2561 | if (nilfs_test_opt(sbi, DISCARD)) { | ||
2562 | int ret = nilfs_discard_segments(nilfs, sci->sc_freesegs, | ||
2563 | sci->sc_nfreesegs); | ||
2564 | if (ret) { | ||
2565 | printk(KERN_WARNING | ||
2566 | "NILFS warning: error %d on discard request, " | ||
2567 | "turning discards off for the device\n", ret); | ||
2568 | nilfs_clear_opt(sbi, DISCARD); | ||
2569 | } | ||
2570 | } | ||
2563 | 2571 | ||
2564 | out_unlock: | 2572 | out_unlock: |
2565 | sci->sc_freesegs = NULL; | 2573 | sci->sc_freesegs = NULL; |
@@ -2573,13 +2581,9 @@ static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode) | |||
2573 | { | 2581 | { |
2574 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 2582 | struct nilfs_sb_info *sbi = sci->sc_sbi; |
2575 | struct nilfs_transaction_info ti; | 2583 | struct nilfs_transaction_info ti; |
2576 | struct nilfs_segctor_req req = { .mode = mode }; | ||
2577 | 2584 | ||
2578 | nilfs_transaction_lock(sbi, &ti, 0); | 2585 | nilfs_transaction_lock(sbi, &ti, 0); |
2579 | 2586 | nilfs_segctor_construct(sci, mode); | |
2580 | nilfs_segctor_accept(sci, &req); | ||
2581 | nilfs_segctor_construct(sci, &req); | ||
2582 | nilfs_segctor_notify(sci, &req); | ||
2583 | 2587 | ||
2584 | /* | 2588 | /* |
2585 | * Unclosed segment should be retried. We do this using sc_timer. | 2589 | * Unclosed segment should be retried. We do this using sc_timer. |
@@ -2635,6 +2639,7 @@ static int nilfs_segctor_flush_mode(struct nilfs_sc_info *sci) | |||
2635 | static int nilfs_segctor_thread(void *arg) | 2639 | static int nilfs_segctor_thread(void *arg) |
2636 | { | 2640 | { |
2637 | struct nilfs_sc_info *sci = (struct nilfs_sc_info *)arg; | 2641 | struct nilfs_sc_info *sci = (struct nilfs_sc_info *)arg; |
2642 | struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs; | ||
2638 | struct timer_list timer; | 2643 | struct timer_list timer; |
2639 | int timeout = 0; | 2644 | int timeout = 0; |
2640 | 2645 | ||
@@ -2680,7 +2685,6 @@ static int nilfs_segctor_thread(void *arg) | |||
2680 | } else { | 2685 | } else { |
2681 | DEFINE_WAIT(wait); | 2686 | DEFINE_WAIT(wait); |
2682 | int should_sleep = 1; | 2687 | int should_sleep = 1; |
2683 | struct the_nilfs *nilfs; | ||
2684 | 2688 | ||
2685 | prepare_to_wait(&sci->sc_wait_daemon, &wait, | 2689 | prepare_to_wait(&sci->sc_wait_daemon, &wait, |
2686 | TASK_INTERRUPTIBLE); | 2690 | TASK_INTERRUPTIBLE); |
@@ -2701,8 +2705,8 @@ static int nilfs_segctor_thread(void *arg) | |||
2701 | finish_wait(&sci->sc_wait_daemon, &wait); | 2705 | finish_wait(&sci->sc_wait_daemon, &wait); |
2702 | timeout = ((sci->sc_state & NILFS_SEGCTOR_COMMIT) && | 2706 | timeout = ((sci->sc_state & NILFS_SEGCTOR_COMMIT) && |
2703 | time_after_eq(jiffies, sci->sc_timer->expires)); | 2707 | time_after_eq(jiffies, sci->sc_timer->expires)); |
2704 | nilfs = sci->sc_sbi->s_nilfs; | 2708 | |
2705 | if (sci->sc_super->s_dirt && nilfs_sb_need_update(nilfs)) | 2709 | if (nilfs_sb_dirty(nilfs) && nilfs_sb_need_update(nilfs)) |
2706 | set_nilfs_discontinued(nilfs); | 2710 | set_nilfs_discontinued(nilfs); |
2707 | } | 2711 | } |
2708 | goto loop; | 2712 | goto loop; |
@@ -2797,12 +2801,9 @@ static void nilfs_segctor_write_out(struct nilfs_sc_info *sci) | |||
2797 | do { | 2801 | do { |
2798 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 2802 | struct nilfs_sb_info *sbi = sci->sc_sbi; |
2799 | struct nilfs_transaction_info ti; | 2803 | struct nilfs_transaction_info ti; |
2800 | struct nilfs_segctor_req req = { .mode = SC_LSEG_SR }; | ||
2801 | 2804 | ||
2802 | nilfs_transaction_lock(sbi, &ti, 0); | 2805 | nilfs_transaction_lock(sbi, &ti, 0); |
2803 | nilfs_segctor_accept(sci, &req); | 2806 | ret = nilfs_segctor_construct(sci, SC_LSEG_SR); |
2804 | ret = nilfs_segctor_construct(sci, &req); | ||
2805 | nilfs_segctor_notify(sci, &req); | ||
2806 | nilfs_transaction_unlock(sbi); | 2807 | nilfs_transaction_unlock(sbi); |
2807 | 2808 | ||
2808 | } while (ret && retrycount-- > 0); | 2809 | } while (ret && retrycount-- > 0); |
@@ -2865,8 +2866,15 @@ int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi) | |||
2865 | struct the_nilfs *nilfs = sbi->s_nilfs; | 2866 | struct the_nilfs *nilfs = sbi->s_nilfs; |
2866 | int err; | 2867 | int err; |
2867 | 2868 | ||
2868 | /* Each field of nilfs_segctor is cleared through the initialization | 2869 | if (NILFS_SC(sbi)) { |
2869 | of super-block info */ | 2870 | /* |
2871 | * This happens if the filesystem was remounted | ||
2872 | * read/write after nilfs_error degenerated it into a | ||
2873 | * read-only mount. | ||
2874 | */ | ||
2875 | nilfs_detach_segment_constructor(sbi); | ||
2876 | } | ||
2877 | |||
2870 | sbi->s_sc_info = nilfs_segctor_new(sbi); | 2878 | sbi->s_sc_info = nilfs_segctor_new(sbi); |
2871 | if (!sbi->s_sc_info) | 2879 | if (!sbi->s_sc_info) |
2872 | return -ENOMEM; | 2880 | return -ENOMEM; |
diff --git a/fs/nilfs2/segment.h b/fs/nilfs2/segment.h index 3d3ab2f9864c..3155e0c7f415 100644 --- a/fs/nilfs2/segment.h +++ b/fs/nilfs2/segment.h | |||
@@ -116,6 +116,7 @@ struct nilfs_segsum_pointer { | |||
116 | * @sc_wait_daemon: Daemon wait queue | 116 | * @sc_wait_daemon: Daemon wait queue |
117 | * @sc_wait_task: Start/end wait queue to control segctord task | 117 | * @sc_wait_task: Start/end wait queue to control segctord task |
118 | * @sc_seq_request: Request counter | 118 | * @sc_seq_request: Request counter |
119 | * @sc_seq_accept: Accepted request count | ||
119 | * @sc_seq_done: Completion counter | 120 | * @sc_seq_done: Completion counter |
120 | * @sc_sync: Request of explicit sync operation | 121 | * @sc_sync: Request of explicit sync operation |
121 | * @sc_interval: Timeout value of background construction | 122 | * @sc_interval: Timeout value of background construction |
@@ -169,6 +170,7 @@ struct nilfs_sc_info { | |||
169 | wait_queue_head_t sc_wait_task; | 170 | wait_queue_head_t sc_wait_task; |
170 | 171 | ||
171 | __u32 sc_seq_request; | 172 | __u32 sc_seq_request; |
173 | __u32 sc_seq_accepted; | ||
172 | __u32 sc_seq_done; | 174 | __u32 sc_seq_done; |
173 | 175 | ||
174 | int sc_sync; | 176 | int sc_sync; |
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c index 8173faee31e6..92579cc4c935 100644 --- a/fs/nilfs2/super.c +++ b/fs/nilfs2/super.c | |||
@@ -96,9 +96,6 @@ void nilfs_error(struct super_block *sb, const char *function, | |||
96 | if (!(sb->s_flags & MS_RDONLY)) { | 96 | if (!(sb->s_flags & MS_RDONLY)) { |
97 | struct the_nilfs *nilfs = sbi->s_nilfs; | 97 | struct the_nilfs *nilfs = sbi->s_nilfs; |
98 | 98 | ||
99 | if (!nilfs_test_opt(sbi, ERRORS_CONT)) | ||
100 | nilfs_detach_segment_constructor(sbi); | ||
101 | |||
102 | down_write(&nilfs->ns_sem); | 99 | down_write(&nilfs->ns_sem); |
103 | if (!(nilfs->ns_mount_state & NILFS_ERROR_FS)) { | 100 | if (!(nilfs->ns_mount_state & NILFS_ERROR_FS)) { |
104 | nilfs->ns_mount_state |= NILFS_ERROR_FS; | 101 | nilfs->ns_mount_state |= NILFS_ERROR_FS; |
@@ -301,7 +298,7 @@ int nilfs_commit_super(struct nilfs_sb_info *sbi, int dupsb) | |||
301 | memcpy(sbp[1], sbp[0], nilfs->ns_sbsize); | 298 | memcpy(sbp[1], sbp[0], nilfs->ns_sbsize); |
302 | nilfs->ns_sbwtime[1] = t; | 299 | nilfs->ns_sbwtime[1] = t; |
303 | } | 300 | } |
304 | sbi->s_super->s_dirt = 0; | 301 | clear_nilfs_sb_dirty(nilfs); |
305 | return nilfs_sync_super(sbi, dupsb); | 302 | return nilfs_sync_super(sbi, dupsb); |
306 | } | 303 | } |
307 | 304 | ||
@@ -345,7 +342,7 @@ static int nilfs_sync_fs(struct super_block *sb, int wait) | |||
345 | err = nilfs_construct_segment(sb); | 342 | err = nilfs_construct_segment(sb); |
346 | 343 | ||
347 | down_write(&nilfs->ns_sem); | 344 | down_write(&nilfs->ns_sem); |
348 | if (sb->s_dirt) | 345 | if (nilfs_sb_dirty(nilfs)) |
349 | nilfs_commit_super(sbi, 1); | 346 | nilfs_commit_super(sbi, 1); |
350 | up_write(&nilfs->ns_sem); | 347 | up_write(&nilfs->ns_sem); |
351 | 348 | ||
@@ -481,6 +478,8 @@ static int nilfs_show_options(struct seq_file *seq, struct vfsmount *vfs) | |||
481 | seq_printf(seq, ",order=strict"); | 478 | seq_printf(seq, ",order=strict"); |
482 | if (nilfs_test_opt(sbi, NORECOVERY)) | 479 | if (nilfs_test_opt(sbi, NORECOVERY)) |
483 | seq_printf(seq, ",norecovery"); | 480 | seq_printf(seq, ",norecovery"); |
481 | if (nilfs_test_opt(sbi, DISCARD)) | ||
482 | seq_printf(seq, ",discard"); | ||
484 | 483 | ||
485 | return 0; | 484 | return 0; |
486 | } | 485 | } |
@@ -550,7 +549,7 @@ static const struct export_operations nilfs_export_ops = { | |||
550 | enum { | 549 | enum { |
551 | Opt_err_cont, Opt_err_panic, Opt_err_ro, | 550 | Opt_err_cont, Opt_err_panic, Opt_err_ro, |
552 | Opt_nobarrier, Opt_snapshot, Opt_order, Opt_norecovery, | 551 | Opt_nobarrier, Opt_snapshot, Opt_order, Opt_norecovery, |
553 | Opt_err, | 552 | Opt_discard, Opt_err, |
554 | }; | 553 | }; |
555 | 554 | ||
556 | static match_table_t tokens = { | 555 | static match_table_t tokens = { |
@@ -561,6 +560,7 @@ static match_table_t tokens = { | |||
561 | {Opt_snapshot, "cp=%u"}, | 560 | {Opt_snapshot, "cp=%u"}, |
562 | {Opt_order, "order=%s"}, | 561 | {Opt_order, "order=%s"}, |
563 | {Opt_norecovery, "norecovery"}, | 562 | {Opt_norecovery, "norecovery"}, |
563 | {Opt_discard, "discard"}, | ||
564 | {Opt_err, NULL} | 564 | {Opt_err, NULL} |
565 | }; | 565 | }; |
566 | 566 | ||
@@ -614,6 +614,9 @@ static int parse_options(char *options, struct super_block *sb) | |||
614 | case Opt_norecovery: | 614 | case Opt_norecovery: |
615 | nilfs_set_opt(sbi, NORECOVERY); | 615 | nilfs_set_opt(sbi, NORECOVERY); |
616 | break; | 616 | break; |
617 | case Opt_discard: | ||
618 | nilfs_set_opt(sbi, DISCARD); | ||
619 | break; | ||
617 | default: | 620 | default: |
618 | printk(KERN_ERR | 621 | printk(KERN_ERR |
619 | "NILFS: Unrecognized mount option \"%s\"\n", p); | 622 | "NILFS: Unrecognized mount option \"%s\"\n", p); |
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index 6241e1722efc..92733d5651d2 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c | |||
@@ -646,6 +646,44 @@ int init_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi, char *data) | |||
646 | goto out; | 646 | goto out; |
647 | } | 647 | } |
648 | 648 | ||
649 | int nilfs_discard_segments(struct the_nilfs *nilfs, __u64 *segnump, | ||
650 | size_t nsegs) | ||
651 | { | ||
652 | sector_t seg_start, seg_end; | ||
653 | sector_t start = 0, nblocks = 0; | ||
654 | unsigned int sects_per_block; | ||
655 | __u64 *sn; | ||
656 | int ret = 0; | ||
657 | |||
658 | sects_per_block = (1 << nilfs->ns_blocksize_bits) / | ||
659 | bdev_logical_block_size(nilfs->ns_bdev); | ||
660 | for (sn = segnump; sn < segnump + nsegs; sn++) { | ||
661 | nilfs_get_segment_range(nilfs, *sn, &seg_start, &seg_end); | ||
662 | |||
663 | if (!nblocks) { | ||
664 | start = seg_start; | ||
665 | nblocks = seg_end - seg_start + 1; | ||
666 | } else if (start + nblocks == seg_start) { | ||
667 | nblocks += seg_end - seg_start + 1; | ||
668 | } else { | ||
669 | ret = blkdev_issue_discard(nilfs->ns_bdev, | ||
670 | start * sects_per_block, | ||
671 | nblocks * sects_per_block, | ||
672 | GFP_NOFS, | ||
673 | DISCARD_FL_BARRIER); | ||
674 | if (ret < 0) | ||
675 | return ret; | ||
676 | nblocks = 0; | ||
677 | } | ||
678 | } | ||
679 | if (nblocks) | ||
680 | ret = blkdev_issue_discard(nilfs->ns_bdev, | ||
681 | start * sects_per_block, | ||
682 | nblocks * sects_per_block, | ||
683 | GFP_NOFS, DISCARD_FL_BARRIER); | ||
684 | return ret; | ||
685 | } | ||
686 | |||
649 | int nilfs_count_free_blocks(struct the_nilfs *nilfs, sector_t *nblocks) | 687 | int nilfs_count_free_blocks(struct the_nilfs *nilfs, sector_t *nblocks) |
650 | { | 688 | { |
651 | struct inode *dat = nilfs_dat_inode(nilfs); | 689 | struct inode *dat = nilfs_dat_inode(nilfs); |
diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h index 589786e33464..e9795f1724d7 100644 --- a/fs/nilfs2/the_nilfs.h +++ b/fs/nilfs2/the_nilfs.h | |||
@@ -38,6 +38,7 @@ enum { | |||
38 | the latest checkpoint was loaded */ | 38 | the latest checkpoint was loaded */ |
39 | THE_NILFS_DISCONTINUED, /* 'next' pointer chain has broken */ | 39 | THE_NILFS_DISCONTINUED, /* 'next' pointer chain has broken */ |
40 | THE_NILFS_GC_RUNNING, /* gc process is running */ | 40 | THE_NILFS_GC_RUNNING, /* gc process is running */ |
41 | THE_NILFS_SB_DIRTY, /* super block is dirty */ | ||
41 | }; | 42 | }; |
42 | 43 | ||
43 | /** | 44 | /** |
@@ -197,6 +198,7 @@ THE_NILFS_FNS(INIT, init) | |||
197 | THE_NILFS_FNS(LOADED, loaded) | 198 | THE_NILFS_FNS(LOADED, loaded) |
198 | THE_NILFS_FNS(DISCONTINUED, discontinued) | 199 | THE_NILFS_FNS(DISCONTINUED, discontinued) |
199 | THE_NILFS_FNS(GC_RUNNING, gc_running) | 200 | THE_NILFS_FNS(GC_RUNNING, gc_running) |
201 | THE_NILFS_FNS(SB_DIRTY, sb_dirty) | ||
200 | 202 | ||
201 | /* Minimum interval of periodical update of superblocks (in seconds) */ | 203 | /* Minimum interval of periodical update of superblocks (in seconds) */ |
202 | #define NILFS_SB_FREQ 10 | 204 | #define NILFS_SB_FREQ 10 |
@@ -221,6 +223,7 @@ struct the_nilfs *find_or_create_nilfs(struct block_device *); | |||
221 | void put_nilfs(struct the_nilfs *); | 223 | void put_nilfs(struct the_nilfs *); |
222 | int init_nilfs(struct the_nilfs *, struct nilfs_sb_info *, char *); | 224 | int init_nilfs(struct the_nilfs *, struct nilfs_sb_info *, char *); |
223 | int load_nilfs(struct the_nilfs *, struct nilfs_sb_info *); | 225 | int load_nilfs(struct the_nilfs *, struct nilfs_sb_info *); |
226 | int nilfs_discard_segments(struct the_nilfs *, __u64 *, size_t); | ||
224 | int nilfs_count_free_blocks(struct the_nilfs *, sector_t *); | 227 | int nilfs_count_free_blocks(struct the_nilfs *, sector_t *); |
225 | struct nilfs_sb_info *nilfs_find_sbinfo(struct the_nilfs *, int, __u64); | 228 | struct nilfs_sb_info *nilfs_find_sbinfo(struct the_nilfs *, int, __u64); |
226 | int nilfs_checkpoint_is_mounted(struct the_nilfs *, __u64, int); | 229 | int nilfs_checkpoint_is_mounted(struct the_nilfs *, __u64, int); |
diff --git a/fs/ocfs2/Makefile b/fs/ocfs2/Makefile index 600d2d2ade11..791c0886c060 100644 --- a/fs/ocfs2/Makefile +++ b/fs/ocfs2/Makefile | |||
@@ -46,6 +46,7 @@ ocfs2_stackglue-objs := stackglue.o | |||
46 | ocfs2_stack_o2cb-objs := stack_o2cb.o | 46 | ocfs2_stack_o2cb-objs := stack_o2cb.o |
47 | ocfs2_stack_user-objs := stack_user.o | 47 | ocfs2_stack_user-objs := stack_user.o |
48 | 48 | ||
49 | obj-$(CONFIG_OCFS2_FS) += dlmfs/ | ||
49 | # cluster/ is always needed when OCFS2_FS for masklog support | 50 | # cluster/ is always needed when OCFS2_FS for masklog support |
50 | obj-$(CONFIG_OCFS2_FS) += cluster/ | 51 | obj-$(CONFIG_OCFS2_FS) += cluster/ |
51 | obj-$(CONFIG_OCFS2_FS_O2CB) += dlm/ | 52 | obj-$(CONFIG_OCFS2_FS_O2CB) += dlm/ |
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index d17bdc718f74..2bbe1ecc08c0 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c | |||
@@ -1050,7 +1050,8 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle, | |||
1050 | strcpy(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE); | 1050 | strcpy(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE); |
1051 | eb->h_blkno = cpu_to_le64(first_blkno); | 1051 | eb->h_blkno = cpu_to_le64(first_blkno); |
1052 | eb->h_fs_generation = cpu_to_le32(osb->fs_generation); | 1052 | eb->h_fs_generation = cpu_to_le32(osb->fs_generation); |
1053 | eb->h_suballoc_slot = cpu_to_le16(osb->slot_num); | 1053 | eb->h_suballoc_slot = |
1054 | cpu_to_le16(meta_ac->ac_alloc_slot); | ||
1054 | eb->h_suballoc_bit = cpu_to_le16(suballoc_bit_start); | 1055 | eb->h_suballoc_bit = cpu_to_le16(suballoc_bit_start); |
1055 | eb->h_list.l_count = | 1056 | eb->h_list.l_count = |
1056 | cpu_to_le16(ocfs2_extent_recs_per_eb(osb->sb)); | 1057 | cpu_to_le16(ocfs2_extent_recs_per_eb(osb->sb)); |
@@ -6037,7 +6038,7 @@ static void ocfs2_truncate_log_worker(struct work_struct *work) | |||
6037 | if (status < 0) | 6038 | if (status < 0) |
6038 | mlog_errno(status); | 6039 | mlog_errno(status); |
6039 | else | 6040 | else |
6040 | ocfs2_init_inode_steal_slot(osb); | 6041 | ocfs2_init_steal_slots(osb); |
6041 | 6042 | ||
6042 | mlog_exit(status); | 6043 | mlog_exit(status); |
6043 | } | 6044 | } |
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 7e9df11260f4..4c2a6d282c4d 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c | |||
@@ -577,8 +577,9 @@ static int ocfs2_direct_IO_get_blocks(struct inode *inode, sector_t iblock, | |||
577 | goto bail; | 577 | goto bail; |
578 | } | 578 | } |
579 | 579 | ||
580 | /* We should already CoW the refcounted extent. */ | 580 | /* We should already CoW the refcounted extent in case of create. */ |
581 | BUG_ON(ext_flags & OCFS2_EXT_REFCOUNTED); | 581 | BUG_ON(create && (ext_flags & OCFS2_EXT_REFCOUNTED)); |
582 | |||
582 | /* | 583 | /* |
583 | * get_more_blocks() expects us to describe a hole by clearing | 584 | * get_more_blocks() expects us to describe a hole by clearing |
584 | * the mapped bit on bh_result(). | 585 | * the mapped bit on bh_result(). |
diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c index 1cd2934de615..b39da877b12f 100644 --- a/fs/ocfs2/cluster/masklog.c +++ b/fs/ocfs2/cluster/masklog.c | |||
@@ -112,6 +112,7 @@ static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = { | |||
112 | define_mask(XATTR), | 112 | define_mask(XATTR), |
113 | define_mask(QUOTA), | 113 | define_mask(QUOTA), |
114 | define_mask(REFCOUNT), | 114 | define_mask(REFCOUNT), |
115 | define_mask(BASTS), | ||
115 | define_mask(ERROR), | 116 | define_mask(ERROR), |
116 | define_mask(NOTICE), | 117 | define_mask(NOTICE), |
117 | define_mask(KTHREAD), | 118 | define_mask(KTHREAD), |
diff --git a/fs/ocfs2/cluster/masklog.h b/fs/ocfs2/cluster/masklog.h index 9b4d11726cf2..3dfddbec32f2 100644 --- a/fs/ocfs2/cluster/masklog.h +++ b/fs/ocfs2/cluster/masklog.h | |||
@@ -114,6 +114,7 @@ | |||
114 | #define ML_XATTR 0x0000000020000000ULL /* ocfs2 extended attributes */ | 114 | #define ML_XATTR 0x0000000020000000ULL /* ocfs2 extended attributes */ |
115 | #define ML_QUOTA 0x0000000040000000ULL /* ocfs2 quota operations */ | 115 | #define ML_QUOTA 0x0000000040000000ULL /* ocfs2 quota operations */ |
116 | #define ML_REFCOUNT 0x0000000080000000ULL /* refcount tree operations */ | 116 | #define ML_REFCOUNT 0x0000000080000000ULL /* refcount tree operations */ |
117 | #define ML_BASTS 0x0000001000000000ULL /* dlmglue asts and basts */ | ||
117 | /* bits that are infrequently given and frequently matched in the high word */ | 118 | /* bits that are infrequently given and frequently matched in the high word */ |
118 | #define ML_ERROR 0x0000000100000000ULL /* sent to KERN_ERR */ | 119 | #define ML_ERROR 0x0000000100000000ULL /* sent to KERN_ERR */ |
119 | #define ML_NOTICE 0x0000000200000000ULL /* setn to KERN_NOTICE */ | 120 | #define ML_NOTICE 0x0000000200000000ULL /* setn to KERN_NOTICE */ |
@@ -194,9 +195,9 @@ extern struct mlog_bits mlog_and_bits, mlog_not_bits; | |||
194 | * previous token if args expands to nothing. | 195 | * previous token if args expands to nothing. |
195 | */ | 196 | */ |
196 | #define __mlog_printk(level, fmt, args...) \ | 197 | #define __mlog_printk(level, fmt, args...) \ |
197 | printk(level "(%u,%lu):%s:%d " fmt, task_pid_nr(current), \ | 198 | printk(level "(%s,%u,%lu):%s:%d " fmt, current->comm, \ |
198 | __mlog_cpu_guess, __PRETTY_FUNCTION__, __LINE__ , \ | 199 | task_pid_nr(current), __mlog_cpu_guess, \ |
199 | ##args) | 200 | __PRETTY_FUNCTION__, __LINE__ , ##args) |
200 | 201 | ||
201 | #define mlog(mask, fmt, args...) do { \ | 202 | #define mlog(mask, fmt, args...) do { \ |
202 | u64 __m = MLOG_MASK_PREFIX | (mask); \ | 203 | u64 __m = MLOG_MASK_PREFIX | (mask); \ |
diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c index 28c3ec238796..765d66c70989 100644 --- a/fs/ocfs2/dir.c +++ b/fs/ocfs2/dir.c | |||
@@ -2439,7 +2439,7 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb, | |||
2439 | dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; | 2439 | dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; |
2440 | memset(dx_root, 0, osb->sb->s_blocksize); | 2440 | memset(dx_root, 0, osb->sb->s_blocksize); |
2441 | strcpy(dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE); | 2441 | strcpy(dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE); |
2442 | dx_root->dr_suballoc_slot = cpu_to_le16(osb->slot_num); | 2442 | dx_root->dr_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot); |
2443 | dx_root->dr_suballoc_bit = cpu_to_le16(dr_suballoc_bit); | 2443 | dx_root->dr_suballoc_bit = cpu_to_le16(dr_suballoc_bit); |
2444 | dx_root->dr_fs_generation = cpu_to_le32(osb->fs_generation); | 2444 | dx_root->dr_fs_generation = cpu_to_le32(osb->fs_generation); |
2445 | dx_root->dr_blkno = cpu_to_le64(dr_blkno); | 2445 | dx_root->dr_blkno = cpu_to_le64(dr_blkno); |
diff --git a/fs/ocfs2/dlm/Makefile b/fs/ocfs2/dlm/Makefile index 190361375700..dcebf0d920fa 100644 --- a/fs/ocfs2/dlm/Makefile +++ b/fs/ocfs2/dlm/Makefile | |||
@@ -1,8 +1,7 @@ | |||
1 | EXTRA_CFLAGS += -Ifs/ocfs2 | 1 | EXTRA_CFLAGS += -Ifs/ocfs2 |
2 | 2 | ||
3 | obj-$(CONFIG_OCFS2_FS_O2CB) += ocfs2_dlm.o ocfs2_dlmfs.o | 3 | obj-$(CONFIG_OCFS2_FS_O2CB) += ocfs2_dlm.o |
4 | 4 | ||
5 | ocfs2_dlm-objs := dlmdomain.o dlmdebug.o dlmthread.o dlmrecovery.o \ | 5 | ocfs2_dlm-objs := dlmdomain.o dlmdebug.o dlmthread.o dlmrecovery.o \ |
6 | dlmmaster.o dlmast.o dlmconvert.o dlmlock.o dlmunlock.o dlmver.o | 6 | dlmmaster.o dlmast.o dlmconvert.o dlmlock.o dlmunlock.o dlmver.o |
7 | 7 | ||
8 | ocfs2_dlmfs-objs := userdlm.o dlmfs.o dlmfsver.o | ||
diff --git a/fs/ocfs2/dlm/dlmrecovery.c b/fs/ocfs2/dlm/dlmrecovery.c index 344bcf90cbf4..b4f99de2caf3 100644 --- a/fs/ocfs2/dlm/dlmrecovery.c +++ b/fs/ocfs2/dlm/dlmrecovery.c | |||
@@ -310,7 +310,7 @@ static int dlm_recovery_thread(void *data) | |||
310 | mlog(0, "dlm thread running for %s...\n", dlm->name); | 310 | mlog(0, "dlm thread running for %s...\n", dlm->name); |
311 | 311 | ||
312 | while (!kthread_should_stop()) { | 312 | while (!kthread_should_stop()) { |
313 | if (dlm_joined(dlm)) { | 313 | if (dlm_domain_fully_joined(dlm)) { |
314 | status = dlm_do_recovery(dlm); | 314 | status = dlm_do_recovery(dlm); |
315 | if (status == -EAGAIN) { | 315 | if (status == -EAGAIN) { |
316 | /* do not sleep, recheck immediately. */ | 316 | /* do not sleep, recheck immediately. */ |
diff --git a/fs/ocfs2/dlmfs/Makefile b/fs/ocfs2/dlmfs/Makefile new file mode 100644 index 000000000000..df69b4856d0d --- /dev/null +++ b/fs/ocfs2/dlmfs/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | EXTRA_CFLAGS += -Ifs/ocfs2 | ||
2 | |||
3 | obj-$(CONFIG_OCFS2_FS) += ocfs2_dlmfs.o | ||
4 | |||
5 | ocfs2_dlmfs-objs := userdlm.o dlmfs.o dlmfsver.o | ||
diff --git a/fs/ocfs2/dlm/dlmfs.c b/fs/ocfs2/dlmfs/dlmfs.c index 02bf17808bdc..1b0de157a08c 100644 --- a/fs/ocfs2/dlm/dlmfs.c +++ b/fs/ocfs2/dlmfs/dlmfs.c | |||
@@ -43,24 +43,17 @@ | |||
43 | #include <linux/init.h> | 43 | #include <linux/init.h> |
44 | #include <linux/string.h> | 44 | #include <linux/string.h> |
45 | #include <linux/backing-dev.h> | 45 | #include <linux/backing-dev.h> |
46 | #include <linux/poll.h> | ||
46 | 47 | ||
47 | #include <asm/uaccess.h> | 48 | #include <asm/uaccess.h> |
48 | 49 | ||
49 | 50 | #include "stackglue.h" | |
50 | #include "cluster/nodemanager.h" | ||
51 | #include "cluster/heartbeat.h" | ||
52 | #include "cluster/tcp.h" | ||
53 | |||
54 | #include "dlmapi.h" | ||
55 | |||
56 | #include "userdlm.h" | 51 | #include "userdlm.h" |
57 | |||
58 | #include "dlmfsver.h" | 52 | #include "dlmfsver.h" |
59 | 53 | ||
60 | #define MLOG_MASK_PREFIX ML_DLMFS | 54 | #define MLOG_MASK_PREFIX ML_DLMFS |
61 | #include "cluster/masklog.h" | 55 | #include "cluster/masklog.h" |
62 | 56 | ||
63 | #include "ocfs2_lockingver.h" | ||
64 | 57 | ||
65 | static const struct super_operations dlmfs_ops; | 58 | static const struct super_operations dlmfs_ops; |
66 | static const struct file_operations dlmfs_file_operations; | 59 | static const struct file_operations dlmfs_file_operations; |
@@ -71,15 +64,46 @@ static struct kmem_cache *dlmfs_inode_cache; | |||
71 | 64 | ||
72 | struct workqueue_struct *user_dlm_worker; | 65 | struct workqueue_struct *user_dlm_worker; |
73 | 66 | ||
67 | |||
68 | |||
74 | /* | 69 | /* |
75 | * This is the userdlmfs locking protocol version. | 70 | * These are the ABI capabilities of dlmfs. |
71 | * | ||
72 | * Over time, dlmfs has added some features that were not part of the | ||
73 | * initial ABI. Unfortunately, some of these features are not detectable | ||
74 | * via standard usage. For example, Linux's default poll always returns | ||
75 | * POLLIN, so there is no way for a caller of poll(2) to know when dlmfs | ||
76 | * added poll support. Instead, we provide this list of new capabilities. | ||
77 | * | ||
78 | * Capabilities is a read-only attribute. We do it as a module parameter | ||
79 | * so we can discover it whether dlmfs is built in, loaded, or even not | ||
80 | * loaded. | ||
76 | * | 81 | * |
77 | * See fs/ocfs2/dlmglue.c for more details on locking versions. | 82 | * The ABI features are local to this machine's dlmfs mount. This is |
83 | * distinct from the locking protocol, which is concerned with inter-node | ||
84 | * interaction. | ||
85 | * | ||
86 | * Capabilities: | ||
87 | * - bast : POLLIN against the file descriptor of a held lock | ||
88 | * signifies a bast fired on the lock. | ||
78 | */ | 89 | */ |
79 | static const struct dlm_protocol_version user_locking_protocol = { | 90 | #define DLMFS_CAPABILITIES "bast stackglue" |
80 | .pv_major = OCFS2_LOCKING_PROTOCOL_MAJOR, | 91 | extern int param_set_dlmfs_capabilities(const char *val, |
81 | .pv_minor = OCFS2_LOCKING_PROTOCOL_MINOR, | 92 | struct kernel_param *kp) |
82 | }; | 93 | { |
94 | printk(KERN_ERR "%s: readonly parameter\n", kp->name); | ||
95 | return -EINVAL; | ||
96 | } | ||
97 | static int param_get_dlmfs_capabilities(char *buffer, | ||
98 | struct kernel_param *kp) | ||
99 | { | ||
100 | return strlcpy(buffer, DLMFS_CAPABILITIES, | ||
101 | strlen(DLMFS_CAPABILITIES) + 1); | ||
102 | } | ||
103 | module_param_call(capabilities, param_set_dlmfs_capabilities, | ||
104 | param_get_dlmfs_capabilities, NULL, 0444); | ||
105 | MODULE_PARM_DESC(capabilities, DLMFS_CAPABILITIES); | ||
106 | |||
83 | 107 | ||
84 | /* | 108 | /* |
85 | * decodes a set of open flags into a valid lock level and a set of flags. | 109 | * decodes a set of open flags into a valid lock level and a set of flags. |
@@ -179,13 +203,46 @@ static int dlmfs_file_release(struct inode *inode, | |||
179 | return 0; | 203 | return 0; |
180 | } | 204 | } |
181 | 205 | ||
206 | /* | ||
207 | * We do ->setattr() just to override size changes. Our size is the size | ||
208 | * of the LVB and nothing else. | ||
209 | */ | ||
210 | static int dlmfs_file_setattr(struct dentry *dentry, struct iattr *attr) | ||
211 | { | ||
212 | int error; | ||
213 | struct inode *inode = dentry->d_inode; | ||
214 | |||
215 | attr->ia_valid &= ~ATTR_SIZE; | ||
216 | error = inode_change_ok(inode, attr); | ||
217 | if (!error) | ||
218 | error = inode_setattr(inode, attr); | ||
219 | |||
220 | return error; | ||
221 | } | ||
222 | |||
223 | static unsigned int dlmfs_file_poll(struct file *file, poll_table *wait) | ||
224 | { | ||
225 | int event = 0; | ||
226 | struct inode *inode = file->f_path.dentry->d_inode; | ||
227 | struct dlmfs_inode_private *ip = DLMFS_I(inode); | ||
228 | |||
229 | poll_wait(file, &ip->ip_lockres.l_event, wait); | ||
230 | |||
231 | spin_lock(&ip->ip_lockres.l_lock); | ||
232 | if (ip->ip_lockres.l_flags & USER_LOCK_BLOCKED) | ||
233 | event = POLLIN | POLLRDNORM; | ||
234 | spin_unlock(&ip->ip_lockres.l_lock); | ||
235 | |||
236 | return event; | ||
237 | } | ||
238 | |||
182 | static ssize_t dlmfs_file_read(struct file *filp, | 239 | static ssize_t dlmfs_file_read(struct file *filp, |
183 | char __user *buf, | 240 | char __user *buf, |
184 | size_t count, | 241 | size_t count, |
185 | loff_t *ppos) | 242 | loff_t *ppos) |
186 | { | 243 | { |
187 | int bytes_left; | 244 | int bytes_left; |
188 | ssize_t readlen; | 245 | ssize_t readlen, got; |
189 | char *lvb_buf; | 246 | char *lvb_buf; |
190 | struct inode *inode = filp->f_path.dentry->d_inode; | 247 | struct inode *inode = filp->f_path.dentry->d_inode; |
191 | 248 | ||
@@ -211,9 +268,13 @@ static ssize_t dlmfs_file_read(struct file *filp, | |||
211 | if (!lvb_buf) | 268 | if (!lvb_buf) |
212 | return -ENOMEM; | 269 | return -ENOMEM; |
213 | 270 | ||
214 | user_dlm_read_lvb(inode, lvb_buf, readlen); | 271 | got = user_dlm_read_lvb(inode, lvb_buf, readlen); |
215 | bytes_left = __copy_to_user(buf, lvb_buf, readlen); | 272 | if (got) { |
216 | readlen -= bytes_left; | 273 | BUG_ON(got != readlen); |
274 | bytes_left = __copy_to_user(buf, lvb_buf, readlen); | ||
275 | readlen -= bytes_left; | ||
276 | } else | ||
277 | readlen = 0; | ||
217 | 278 | ||
218 | kfree(lvb_buf); | 279 | kfree(lvb_buf); |
219 | 280 | ||
@@ -272,7 +333,7 @@ static void dlmfs_init_once(void *foo) | |||
272 | struct dlmfs_inode_private *ip = | 333 | struct dlmfs_inode_private *ip = |
273 | (struct dlmfs_inode_private *) foo; | 334 | (struct dlmfs_inode_private *) foo; |
274 | 335 | ||
275 | ip->ip_dlm = NULL; | 336 | ip->ip_conn = NULL; |
276 | ip->ip_parent = NULL; | 337 | ip->ip_parent = NULL; |
277 | 338 | ||
278 | inode_init_once(&ip->ip_vfs_inode); | 339 | inode_init_once(&ip->ip_vfs_inode); |
@@ -314,14 +375,14 @@ static void dlmfs_clear_inode(struct inode *inode) | |||
314 | goto clear_fields; | 375 | goto clear_fields; |
315 | } | 376 | } |
316 | 377 | ||
317 | mlog(0, "we're a directory, ip->ip_dlm = 0x%p\n", ip->ip_dlm); | 378 | mlog(0, "we're a directory, ip->ip_conn = 0x%p\n", ip->ip_conn); |
318 | /* we must be a directory. If required, lets unregister the | 379 | /* we must be a directory. If required, lets unregister the |
319 | * dlm context now. */ | 380 | * dlm context now. */ |
320 | if (ip->ip_dlm) | 381 | if (ip->ip_conn) |
321 | user_dlm_unregister_context(ip->ip_dlm); | 382 | user_dlm_unregister(ip->ip_conn); |
322 | clear_fields: | 383 | clear_fields: |
323 | ip->ip_parent = NULL; | 384 | ip->ip_parent = NULL; |
324 | ip->ip_dlm = NULL; | 385 | ip->ip_conn = NULL; |
325 | } | 386 | } |
326 | 387 | ||
327 | static struct backing_dev_info dlmfs_backing_dev_info = { | 388 | static struct backing_dev_info dlmfs_backing_dev_info = { |
@@ -371,7 +432,7 @@ static struct inode *dlmfs_get_inode(struct inode *parent, | |||
371 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; | 432 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
372 | 433 | ||
373 | ip = DLMFS_I(inode); | 434 | ip = DLMFS_I(inode); |
374 | ip->ip_dlm = DLMFS_I(parent)->ip_dlm; | 435 | ip->ip_conn = DLMFS_I(parent)->ip_conn; |
375 | 436 | ||
376 | switch (mode & S_IFMT) { | 437 | switch (mode & S_IFMT) { |
377 | default: | 438 | default: |
@@ -425,13 +486,12 @@ static int dlmfs_mkdir(struct inode * dir, | |||
425 | struct inode *inode = NULL; | 486 | struct inode *inode = NULL; |
426 | struct qstr *domain = &dentry->d_name; | 487 | struct qstr *domain = &dentry->d_name; |
427 | struct dlmfs_inode_private *ip; | 488 | struct dlmfs_inode_private *ip; |
428 | struct dlm_ctxt *dlm; | 489 | struct ocfs2_cluster_connection *conn; |
429 | struct dlm_protocol_version proto = user_locking_protocol; | ||
430 | 490 | ||
431 | mlog(0, "mkdir %.*s\n", domain->len, domain->name); | 491 | mlog(0, "mkdir %.*s\n", domain->len, domain->name); |
432 | 492 | ||
433 | /* verify that we have a proper domain */ | 493 | /* verify that we have a proper domain */ |
434 | if (domain->len >= O2NM_MAX_NAME_LEN) { | 494 | if (domain->len >= GROUP_NAME_MAX) { |
435 | status = -EINVAL; | 495 | status = -EINVAL; |
436 | mlog(ML_ERROR, "invalid domain name for directory.\n"); | 496 | mlog(ML_ERROR, "invalid domain name for directory.\n"); |
437 | goto bail; | 497 | goto bail; |
@@ -446,14 +506,14 @@ static int dlmfs_mkdir(struct inode * dir, | |||
446 | 506 | ||
447 | ip = DLMFS_I(inode); | 507 | ip = DLMFS_I(inode); |
448 | 508 | ||
449 | dlm = user_dlm_register_context(domain, &proto); | 509 | conn = user_dlm_register(domain); |
450 | if (IS_ERR(dlm)) { | 510 | if (IS_ERR(conn)) { |
451 | status = PTR_ERR(dlm); | 511 | status = PTR_ERR(conn); |
452 | mlog(ML_ERROR, "Error %d could not register domain \"%.*s\"\n", | 512 | mlog(ML_ERROR, "Error %d could not register domain \"%.*s\"\n", |
453 | status, domain->len, domain->name); | 513 | status, domain->len, domain->name); |
454 | goto bail; | 514 | goto bail; |
455 | } | 515 | } |
456 | ip->ip_dlm = dlm; | 516 | ip->ip_conn = conn; |
457 | 517 | ||
458 | inc_nlink(dir); | 518 | inc_nlink(dir); |
459 | d_instantiate(dentry, inode); | 519 | d_instantiate(dentry, inode); |
@@ -549,6 +609,7 @@ static int dlmfs_fill_super(struct super_block * sb, | |||
549 | static const struct file_operations dlmfs_file_operations = { | 609 | static const struct file_operations dlmfs_file_operations = { |
550 | .open = dlmfs_file_open, | 610 | .open = dlmfs_file_open, |
551 | .release = dlmfs_file_release, | 611 | .release = dlmfs_file_release, |
612 | .poll = dlmfs_file_poll, | ||
552 | .read = dlmfs_file_read, | 613 | .read = dlmfs_file_read, |
553 | .write = dlmfs_file_write, | 614 | .write = dlmfs_file_write, |
554 | }; | 615 | }; |
@@ -576,6 +637,7 @@ static const struct super_operations dlmfs_ops = { | |||
576 | 637 | ||
577 | static const struct inode_operations dlmfs_file_inode_operations = { | 638 | static const struct inode_operations dlmfs_file_inode_operations = { |
578 | .getattr = simple_getattr, | 639 | .getattr = simple_getattr, |
640 | .setattr = dlmfs_file_setattr, | ||
579 | }; | 641 | }; |
580 | 642 | ||
581 | static int dlmfs_get_sb(struct file_system_type *fs_type, | 643 | static int dlmfs_get_sb(struct file_system_type *fs_type, |
@@ -620,6 +682,7 @@ static int __init init_dlmfs_fs(void) | |||
620 | } | 682 | } |
621 | cleanup_worker = 1; | 683 | cleanup_worker = 1; |
622 | 684 | ||
685 | user_dlm_set_locking_protocol(); | ||
623 | status = register_filesystem(&dlmfs_fs_type); | 686 | status = register_filesystem(&dlmfs_fs_type); |
624 | bail: | 687 | bail: |
625 | if (status) { | 688 | if (status) { |
diff --git a/fs/ocfs2/dlm/dlmfsver.c b/fs/ocfs2/dlmfs/dlmfsver.c index a733b3321f83..a733b3321f83 100644 --- a/fs/ocfs2/dlm/dlmfsver.c +++ b/fs/ocfs2/dlmfs/dlmfsver.c | |||
diff --git a/fs/ocfs2/dlm/dlmfsver.h b/fs/ocfs2/dlmfs/dlmfsver.h index f35eadbed25c..f35eadbed25c 100644 --- a/fs/ocfs2/dlm/dlmfsver.h +++ b/fs/ocfs2/dlmfs/dlmfsver.h | |||
diff --git a/fs/ocfs2/dlm/userdlm.c b/fs/ocfs2/dlmfs/userdlm.c index 4cb1d3dae250..0499e3fb7bdb 100644 --- a/fs/ocfs2/dlm/userdlm.c +++ b/fs/ocfs2/dlmfs/userdlm.c | |||
@@ -34,18 +34,19 @@ | |||
34 | #include <linux/types.h> | 34 | #include <linux/types.h> |
35 | #include <linux/crc32.h> | 35 | #include <linux/crc32.h> |
36 | 36 | ||
37 | 37 | #include "ocfs2_lockingver.h" | |
38 | #include "cluster/nodemanager.h" | 38 | #include "stackglue.h" |
39 | #include "cluster/heartbeat.h" | ||
40 | #include "cluster/tcp.h" | ||
41 | |||
42 | #include "dlmapi.h" | ||
43 | |||
44 | #include "userdlm.h" | 39 | #include "userdlm.h" |
45 | 40 | ||
46 | #define MLOG_MASK_PREFIX ML_DLMFS | 41 | #define MLOG_MASK_PREFIX ML_DLMFS |
47 | #include "cluster/masklog.h" | 42 | #include "cluster/masklog.h" |
48 | 43 | ||
44 | |||
45 | static inline struct user_lock_res *user_lksb_to_lock_res(struct ocfs2_dlm_lksb *lksb) | ||
46 | { | ||
47 | return container_of(lksb, struct user_lock_res, l_lksb); | ||
48 | } | ||
49 | |||
49 | static inline int user_check_wait_flag(struct user_lock_res *lockres, | 50 | static inline int user_check_wait_flag(struct user_lock_res *lockres, |
50 | int flag) | 51 | int flag) |
51 | { | 52 | { |
@@ -73,15 +74,15 @@ static inline void user_wait_on_blocked_lock(struct user_lock_res *lockres) | |||
73 | } | 74 | } |
74 | 75 | ||
75 | /* I heart container_of... */ | 76 | /* I heart container_of... */ |
76 | static inline struct dlm_ctxt * | 77 | static inline struct ocfs2_cluster_connection * |
77 | dlm_ctxt_from_user_lockres(struct user_lock_res *lockres) | 78 | cluster_connection_from_user_lockres(struct user_lock_res *lockres) |
78 | { | 79 | { |
79 | struct dlmfs_inode_private *ip; | 80 | struct dlmfs_inode_private *ip; |
80 | 81 | ||
81 | ip = container_of(lockres, | 82 | ip = container_of(lockres, |
82 | struct dlmfs_inode_private, | 83 | struct dlmfs_inode_private, |
83 | ip_lockres); | 84 | ip_lockres); |
84 | return ip->ip_dlm; | 85 | return ip->ip_conn; |
85 | } | 86 | } |
86 | 87 | ||
87 | static struct inode * | 88 | static struct inode * |
@@ -103,9 +104,9 @@ static inline void user_recover_from_dlm_error(struct user_lock_res *lockres) | |||
103 | } | 104 | } |
104 | 105 | ||
105 | #define user_log_dlm_error(_func, _stat, _lockres) do { \ | 106 | #define user_log_dlm_error(_func, _stat, _lockres) do { \ |
106 | mlog(ML_ERROR, "Dlm error \"%s\" while calling %s on " \ | 107 | mlog(ML_ERROR, "Dlm error %d while calling %s on " \ |
107 | "resource %.*s: %s\n", dlm_errname(_stat), _func, \ | 108 | "resource %.*s\n", _stat, _func, \ |
108 | _lockres->l_namelen, _lockres->l_name, dlm_errmsg(_stat)); \ | 109 | _lockres->l_namelen, _lockres->l_name); \ |
109 | } while (0) | 110 | } while (0) |
110 | 111 | ||
111 | /* WARNING: This function lives in a world where the only three lock | 112 | /* WARNING: This function lives in a world where the only three lock |
@@ -113,34 +114,35 @@ static inline void user_recover_from_dlm_error(struct user_lock_res *lockres) | |||
113 | * lock types are added. */ | 114 | * lock types are added. */ |
114 | static inline int user_highest_compat_lock_level(int level) | 115 | static inline int user_highest_compat_lock_level(int level) |
115 | { | 116 | { |
116 | int new_level = LKM_EXMODE; | 117 | int new_level = DLM_LOCK_EX; |
117 | 118 | ||
118 | if (level == LKM_EXMODE) | 119 | if (level == DLM_LOCK_EX) |
119 | new_level = LKM_NLMODE; | 120 | new_level = DLM_LOCK_NL; |
120 | else if (level == LKM_PRMODE) | 121 | else if (level == DLM_LOCK_PR) |
121 | new_level = LKM_PRMODE; | 122 | new_level = DLM_LOCK_PR; |
122 | return new_level; | 123 | return new_level; |
123 | } | 124 | } |
124 | 125 | ||
125 | static void user_ast(void *opaque) | 126 | static void user_ast(struct ocfs2_dlm_lksb *lksb) |
126 | { | 127 | { |
127 | struct user_lock_res *lockres = opaque; | 128 | struct user_lock_res *lockres = user_lksb_to_lock_res(lksb); |
128 | struct dlm_lockstatus *lksb; | 129 | int status; |
129 | 130 | ||
130 | mlog(0, "AST fired for lockres %.*s\n", lockres->l_namelen, | 131 | mlog(ML_BASTS, "AST fired for lockres %.*s, level %d => %d\n", |
131 | lockres->l_name); | 132 | lockres->l_namelen, lockres->l_name, lockres->l_level, |
133 | lockres->l_requested); | ||
132 | 134 | ||
133 | spin_lock(&lockres->l_lock); | 135 | spin_lock(&lockres->l_lock); |
134 | 136 | ||
135 | lksb = &(lockres->l_lksb); | 137 | status = ocfs2_dlm_lock_status(&lockres->l_lksb); |
136 | if (lksb->status != DLM_NORMAL) { | 138 | if (status) { |
137 | mlog(ML_ERROR, "lksb status value of %u on lockres %.*s\n", | 139 | mlog(ML_ERROR, "lksb status value of %u on lockres %.*s\n", |
138 | lksb->status, lockres->l_namelen, lockres->l_name); | 140 | status, lockres->l_namelen, lockres->l_name); |
139 | spin_unlock(&lockres->l_lock); | 141 | spin_unlock(&lockres->l_lock); |
140 | return; | 142 | return; |
141 | } | 143 | } |
142 | 144 | ||
143 | mlog_bug_on_msg(lockres->l_requested == LKM_IVMODE, | 145 | mlog_bug_on_msg(lockres->l_requested == DLM_LOCK_IV, |
144 | "Lockres %.*s, requested ivmode. flags 0x%x\n", | 146 | "Lockres %.*s, requested ivmode. flags 0x%x\n", |
145 | lockres->l_namelen, lockres->l_name, lockres->l_flags); | 147 | lockres->l_namelen, lockres->l_name, lockres->l_flags); |
146 | 148 | ||
@@ -148,13 +150,13 @@ static void user_ast(void *opaque) | |||
148 | if (lockres->l_requested < lockres->l_level) { | 150 | if (lockres->l_requested < lockres->l_level) { |
149 | if (lockres->l_requested <= | 151 | if (lockres->l_requested <= |
150 | user_highest_compat_lock_level(lockres->l_blocking)) { | 152 | user_highest_compat_lock_level(lockres->l_blocking)) { |
151 | lockres->l_blocking = LKM_NLMODE; | 153 | lockres->l_blocking = DLM_LOCK_NL; |
152 | lockres->l_flags &= ~USER_LOCK_BLOCKED; | 154 | lockres->l_flags &= ~USER_LOCK_BLOCKED; |
153 | } | 155 | } |
154 | } | 156 | } |
155 | 157 | ||
156 | lockres->l_level = lockres->l_requested; | 158 | lockres->l_level = lockres->l_requested; |
157 | lockres->l_requested = LKM_IVMODE; | 159 | lockres->l_requested = DLM_LOCK_IV; |
158 | lockres->l_flags |= USER_LOCK_ATTACHED; | 160 | lockres->l_flags |= USER_LOCK_ATTACHED; |
159 | lockres->l_flags &= ~USER_LOCK_BUSY; | 161 | lockres->l_flags &= ~USER_LOCK_BUSY; |
160 | 162 | ||
@@ -193,11 +195,11 @@ static void __user_dlm_cond_queue_lockres(struct user_lock_res *lockres) | |||
193 | return; | 195 | return; |
194 | 196 | ||
195 | switch (lockres->l_blocking) { | 197 | switch (lockres->l_blocking) { |
196 | case LKM_EXMODE: | 198 | case DLM_LOCK_EX: |
197 | if (!lockres->l_ex_holders && !lockres->l_ro_holders) | 199 | if (!lockres->l_ex_holders && !lockres->l_ro_holders) |
198 | queue = 1; | 200 | queue = 1; |
199 | break; | 201 | break; |
200 | case LKM_PRMODE: | 202 | case DLM_LOCK_PR: |
201 | if (!lockres->l_ex_holders) | 203 | if (!lockres->l_ex_holders) |
202 | queue = 1; | 204 | queue = 1; |
203 | break; | 205 | break; |
@@ -209,12 +211,12 @@ static void __user_dlm_cond_queue_lockres(struct user_lock_res *lockres) | |||
209 | __user_dlm_queue_lockres(lockres); | 211 | __user_dlm_queue_lockres(lockres); |
210 | } | 212 | } |
211 | 213 | ||
212 | static void user_bast(void *opaque, int level) | 214 | static void user_bast(struct ocfs2_dlm_lksb *lksb, int level) |
213 | { | 215 | { |
214 | struct user_lock_res *lockres = opaque; | 216 | struct user_lock_res *lockres = user_lksb_to_lock_res(lksb); |
215 | 217 | ||
216 | mlog(0, "Blocking AST fired for lockres %.*s. Blocking level %d\n", | 218 | mlog(ML_BASTS, "BAST fired for lockres %.*s, blocking %d, level %d\n", |
217 | lockres->l_namelen, lockres->l_name, level); | 219 | lockres->l_namelen, lockres->l_name, level, lockres->l_level); |
218 | 220 | ||
219 | spin_lock(&lockres->l_lock); | 221 | spin_lock(&lockres->l_lock); |
220 | lockres->l_flags |= USER_LOCK_BLOCKED; | 222 | lockres->l_flags |= USER_LOCK_BLOCKED; |
@@ -227,15 +229,15 @@ static void user_bast(void *opaque, int level) | |||
227 | wake_up(&lockres->l_event); | 229 | wake_up(&lockres->l_event); |
228 | } | 230 | } |
229 | 231 | ||
230 | static void user_unlock_ast(void *opaque, enum dlm_status status) | 232 | static void user_unlock_ast(struct ocfs2_dlm_lksb *lksb, int status) |
231 | { | 233 | { |
232 | struct user_lock_res *lockres = opaque; | 234 | struct user_lock_res *lockres = user_lksb_to_lock_res(lksb); |
233 | 235 | ||
234 | mlog(0, "UNLOCK AST called on lock %.*s\n", lockres->l_namelen, | 236 | mlog(ML_BASTS, "UNLOCK AST fired for lockres %.*s, flags 0x%x\n", |
235 | lockres->l_name); | 237 | lockres->l_namelen, lockres->l_name, lockres->l_flags); |
236 | 238 | ||
237 | if (status != DLM_NORMAL && status != DLM_CANCELGRANT) | 239 | if (status) |
238 | mlog(ML_ERROR, "Dlm returns status %d\n", status); | 240 | mlog(ML_ERROR, "dlm returns status %d\n", status); |
239 | 241 | ||
240 | spin_lock(&lockres->l_lock); | 242 | spin_lock(&lockres->l_lock); |
241 | /* The teardown flag gets set early during the unlock process, | 243 | /* The teardown flag gets set early during the unlock process, |
@@ -243,7 +245,7 @@ static void user_unlock_ast(void *opaque, enum dlm_status status) | |||
243 | * for a concurrent cancel. */ | 245 | * for a concurrent cancel. */ |
244 | if (lockres->l_flags & USER_LOCK_IN_TEARDOWN | 246 | if (lockres->l_flags & USER_LOCK_IN_TEARDOWN |
245 | && !(lockres->l_flags & USER_LOCK_IN_CANCEL)) { | 247 | && !(lockres->l_flags & USER_LOCK_IN_CANCEL)) { |
246 | lockres->l_level = LKM_IVMODE; | 248 | lockres->l_level = DLM_LOCK_IV; |
247 | } else if (status == DLM_CANCELGRANT) { | 249 | } else if (status == DLM_CANCELGRANT) { |
248 | /* We tried to cancel a convert request, but it was | 250 | /* We tried to cancel a convert request, but it was |
249 | * already granted. Don't clear the busy flag - the | 251 | * already granted. Don't clear the busy flag - the |
@@ -254,7 +256,7 @@ static void user_unlock_ast(void *opaque, enum dlm_status status) | |||
254 | } else { | 256 | } else { |
255 | BUG_ON(!(lockres->l_flags & USER_LOCK_IN_CANCEL)); | 257 | BUG_ON(!(lockres->l_flags & USER_LOCK_IN_CANCEL)); |
256 | /* Cancel succeeded, we want to re-queue */ | 258 | /* Cancel succeeded, we want to re-queue */ |
257 | lockres->l_requested = LKM_IVMODE; /* cancel an | 259 | lockres->l_requested = DLM_LOCK_IV; /* cancel an |
258 | * upconvert | 260 | * upconvert |
259 | * request. */ | 261 | * request. */ |
260 | lockres->l_flags &= ~USER_LOCK_IN_CANCEL; | 262 | lockres->l_flags &= ~USER_LOCK_IN_CANCEL; |
@@ -271,6 +273,21 @@ out_noclear: | |||
271 | wake_up(&lockres->l_event); | 273 | wake_up(&lockres->l_event); |
272 | } | 274 | } |
273 | 275 | ||
276 | /* | ||
277 | * This is the userdlmfs locking protocol version. | ||
278 | * | ||
279 | * See fs/ocfs2/dlmglue.c for more details on locking versions. | ||
280 | */ | ||
281 | static struct ocfs2_locking_protocol user_dlm_lproto = { | ||
282 | .lp_max_version = { | ||
283 | .pv_major = OCFS2_LOCKING_PROTOCOL_MAJOR, | ||
284 | .pv_minor = OCFS2_LOCKING_PROTOCOL_MINOR, | ||
285 | }, | ||
286 | .lp_lock_ast = user_ast, | ||
287 | .lp_blocking_ast = user_bast, | ||
288 | .lp_unlock_ast = user_unlock_ast, | ||
289 | }; | ||
290 | |||
274 | static inline void user_dlm_drop_inode_ref(struct user_lock_res *lockres) | 291 | static inline void user_dlm_drop_inode_ref(struct user_lock_res *lockres) |
275 | { | 292 | { |
276 | struct inode *inode; | 293 | struct inode *inode; |
@@ -283,10 +300,10 @@ static void user_dlm_unblock_lock(struct work_struct *work) | |||
283 | int new_level, status; | 300 | int new_level, status; |
284 | struct user_lock_res *lockres = | 301 | struct user_lock_res *lockres = |
285 | container_of(work, struct user_lock_res, l_work); | 302 | container_of(work, struct user_lock_res, l_work); |
286 | struct dlm_ctxt *dlm = dlm_ctxt_from_user_lockres(lockres); | 303 | struct ocfs2_cluster_connection *conn = |
304 | cluster_connection_from_user_lockres(lockres); | ||
287 | 305 | ||
288 | mlog(0, "processing lockres %.*s\n", lockres->l_namelen, | 306 | mlog(0, "lockres %.*s\n", lockres->l_namelen, lockres->l_name); |
289 | lockres->l_name); | ||
290 | 307 | ||
291 | spin_lock(&lockres->l_lock); | 308 | spin_lock(&lockres->l_lock); |
292 | 309 | ||
@@ -304,17 +321,23 @@ static void user_dlm_unblock_lock(struct work_struct *work) | |||
304 | * flag, and finally we might get another bast which re-queues | 321 | * flag, and finally we might get another bast which re-queues |
305 | * us before our ast for the downconvert is called. */ | 322 | * us before our ast for the downconvert is called. */ |
306 | if (!(lockres->l_flags & USER_LOCK_BLOCKED)) { | 323 | if (!(lockres->l_flags & USER_LOCK_BLOCKED)) { |
324 | mlog(ML_BASTS, "lockres %.*s USER_LOCK_BLOCKED\n", | ||
325 | lockres->l_namelen, lockres->l_name); | ||
307 | spin_unlock(&lockres->l_lock); | 326 | spin_unlock(&lockres->l_lock); |
308 | goto drop_ref; | 327 | goto drop_ref; |
309 | } | 328 | } |
310 | 329 | ||
311 | if (lockres->l_flags & USER_LOCK_IN_TEARDOWN) { | 330 | if (lockres->l_flags & USER_LOCK_IN_TEARDOWN) { |
331 | mlog(ML_BASTS, "lockres %.*s USER_LOCK_IN_TEARDOWN\n", | ||
332 | lockres->l_namelen, lockres->l_name); | ||
312 | spin_unlock(&lockres->l_lock); | 333 | spin_unlock(&lockres->l_lock); |
313 | goto drop_ref; | 334 | goto drop_ref; |
314 | } | 335 | } |
315 | 336 | ||
316 | if (lockres->l_flags & USER_LOCK_BUSY) { | 337 | if (lockres->l_flags & USER_LOCK_BUSY) { |
317 | if (lockres->l_flags & USER_LOCK_IN_CANCEL) { | 338 | if (lockres->l_flags & USER_LOCK_IN_CANCEL) { |
339 | mlog(ML_BASTS, "lockres %.*s USER_LOCK_IN_CANCEL\n", | ||
340 | lockres->l_namelen, lockres->l_name); | ||
318 | spin_unlock(&lockres->l_lock); | 341 | spin_unlock(&lockres->l_lock); |
319 | goto drop_ref; | 342 | goto drop_ref; |
320 | } | 343 | } |
@@ -322,32 +345,31 @@ static void user_dlm_unblock_lock(struct work_struct *work) | |||
322 | lockres->l_flags |= USER_LOCK_IN_CANCEL; | 345 | lockres->l_flags |= USER_LOCK_IN_CANCEL; |
323 | spin_unlock(&lockres->l_lock); | 346 | spin_unlock(&lockres->l_lock); |
324 | 347 | ||
325 | status = dlmunlock(dlm, | 348 | status = ocfs2_dlm_unlock(conn, &lockres->l_lksb, |
326 | &lockres->l_lksb, | 349 | DLM_LKF_CANCEL); |
327 | LKM_CANCEL, | 350 | if (status) |
328 | user_unlock_ast, | 351 | user_log_dlm_error("ocfs2_dlm_unlock", status, lockres); |
329 | lockres); | ||
330 | if (status != DLM_NORMAL) | ||
331 | user_log_dlm_error("dlmunlock", status, lockres); | ||
332 | goto drop_ref; | 352 | goto drop_ref; |
333 | } | 353 | } |
334 | 354 | ||
335 | /* If there are still incompat holders, we can exit safely | 355 | /* If there are still incompat holders, we can exit safely |
336 | * without worrying about re-queueing this lock as that will | 356 | * without worrying about re-queueing this lock as that will |
337 | * happen on the last call to user_cluster_unlock. */ | 357 | * happen on the last call to user_cluster_unlock. */ |
338 | if ((lockres->l_blocking == LKM_EXMODE) | 358 | if ((lockres->l_blocking == DLM_LOCK_EX) |
339 | && (lockres->l_ex_holders || lockres->l_ro_holders)) { | 359 | && (lockres->l_ex_holders || lockres->l_ro_holders)) { |
340 | spin_unlock(&lockres->l_lock); | 360 | spin_unlock(&lockres->l_lock); |
341 | mlog(0, "can't downconvert for ex: ro = %u, ex = %u\n", | 361 | mlog(ML_BASTS, "lockres %.*s, EX/PR Holders %u,%u\n", |
342 | lockres->l_ro_holders, lockres->l_ex_holders); | 362 | lockres->l_namelen, lockres->l_name, |
363 | lockres->l_ex_holders, lockres->l_ro_holders); | ||
343 | goto drop_ref; | 364 | goto drop_ref; |
344 | } | 365 | } |
345 | 366 | ||
346 | if ((lockres->l_blocking == LKM_PRMODE) | 367 | if ((lockres->l_blocking == DLM_LOCK_PR) |
347 | && lockres->l_ex_holders) { | 368 | && lockres->l_ex_holders) { |
348 | spin_unlock(&lockres->l_lock); | 369 | spin_unlock(&lockres->l_lock); |
349 | mlog(0, "can't downconvert for pr: ex = %u\n", | 370 | mlog(ML_BASTS, "lockres %.*s, EX Holders %u\n", |
350 | lockres->l_ex_holders); | 371 | lockres->l_namelen, lockres->l_name, |
372 | lockres->l_ex_holders); | ||
351 | goto drop_ref; | 373 | goto drop_ref; |
352 | } | 374 | } |
353 | 375 | ||
@@ -355,22 +377,17 @@ static void user_dlm_unblock_lock(struct work_struct *work) | |||
355 | new_level = user_highest_compat_lock_level(lockres->l_blocking); | 377 | new_level = user_highest_compat_lock_level(lockres->l_blocking); |
356 | lockres->l_requested = new_level; | 378 | lockres->l_requested = new_level; |
357 | lockres->l_flags |= USER_LOCK_BUSY; | 379 | lockres->l_flags |= USER_LOCK_BUSY; |
358 | mlog(0, "Downconvert lock from %d to %d\n", | 380 | mlog(ML_BASTS, "lockres %.*s, downconvert %d => %d\n", |
359 | lockres->l_level, new_level); | 381 | lockres->l_namelen, lockres->l_name, lockres->l_level, new_level); |
360 | spin_unlock(&lockres->l_lock); | 382 | spin_unlock(&lockres->l_lock); |
361 | 383 | ||
362 | /* need lock downconvert request now... */ | 384 | /* need lock downconvert request now... */ |
363 | status = dlmlock(dlm, | 385 | status = ocfs2_dlm_lock(conn, new_level, &lockres->l_lksb, |
364 | new_level, | 386 | DLM_LKF_CONVERT|DLM_LKF_VALBLK, |
365 | &lockres->l_lksb, | 387 | lockres->l_name, |
366 | LKM_CONVERT|LKM_VALBLK, | 388 | lockres->l_namelen); |
367 | lockres->l_name, | 389 | if (status) { |
368 | lockres->l_namelen, | 390 | user_log_dlm_error("ocfs2_dlm_lock", status, lockres); |
369 | user_ast, | ||
370 | lockres, | ||
371 | user_bast); | ||
372 | if (status != DLM_NORMAL) { | ||
373 | user_log_dlm_error("dlmlock", status, lockres); | ||
374 | user_recover_from_dlm_error(lockres); | 391 | user_recover_from_dlm_error(lockres); |
375 | } | 392 | } |
376 | 393 | ||
@@ -382,10 +399,10 @@ static inline void user_dlm_inc_holders(struct user_lock_res *lockres, | |||
382 | int level) | 399 | int level) |
383 | { | 400 | { |
384 | switch(level) { | 401 | switch(level) { |
385 | case LKM_EXMODE: | 402 | case DLM_LOCK_EX: |
386 | lockres->l_ex_holders++; | 403 | lockres->l_ex_holders++; |
387 | break; | 404 | break; |
388 | case LKM_PRMODE: | 405 | case DLM_LOCK_PR: |
389 | lockres->l_ro_holders++; | 406 | lockres->l_ro_holders++; |
390 | break; | 407 | break; |
391 | default: | 408 | default: |
@@ -410,20 +427,19 @@ int user_dlm_cluster_lock(struct user_lock_res *lockres, | |||
410 | int lkm_flags) | 427 | int lkm_flags) |
411 | { | 428 | { |
412 | int status, local_flags; | 429 | int status, local_flags; |
413 | struct dlm_ctxt *dlm = dlm_ctxt_from_user_lockres(lockres); | 430 | struct ocfs2_cluster_connection *conn = |
431 | cluster_connection_from_user_lockres(lockres); | ||
414 | 432 | ||
415 | if (level != LKM_EXMODE && | 433 | if (level != DLM_LOCK_EX && |
416 | level != LKM_PRMODE) { | 434 | level != DLM_LOCK_PR) { |
417 | mlog(ML_ERROR, "lockres %.*s: invalid request!\n", | 435 | mlog(ML_ERROR, "lockres %.*s: invalid request!\n", |
418 | lockres->l_namelen, lockres->l_name); | 436 | lockres->l_namelen, lockres->l_name); |
419 | status = -EINVAL; | 437 | status = -EINVAL; |
420 | goto bail; | 438 | goto bail; |
421 | } | 439 | } |
422 | 440 | ||
423 | mlog(0, "lockres %.*s: asking for %s lock, passed flags = 0x%x\n", | 441 | mlog(ML_BASTS, "lockres %.*s, level %d, flags = 0x%x\n", |
424 | lockres->l_namelen, lockres->l_name, | 442 | lockres->l_namelen, lockres->l_name, level, lkm_flags); |
425 | (level == LKM_EXMODE) ? "LKM_EXMODE" : "LKM_PRMODE", | ||
426 | lkm_flags); | ||
427 | 443 | ||
428 | again: | 444 | again: |
429 | if (signal_pending(current)) { | 445 | if (signal_pending(current)) { |
@@ -457,35 +473,26 @@ again: | |||
457 | } | 473 | } |
458 | 474 | ||
459 | if (level > lockres->l_level) { | 475 | if (level > lockres->l_level) { |
460 | local_flags = lkm_flags | LKM_VALBLK; | 476 | local_flags = lkm_flags | DLM_LKF_VALBLK; |
461 | if (lockres->l_level != LKM_IVMODE) | 477 | if (lockres->l_level != DLM_LOCK_IV) |
462 | local_flags |= LKM_CONVERT; | 478 | local_flags |= DLM_LKF_CONVERT; |
463 | 479 | ||
464 | lockres->l_requested = level; | 480 | lockres->l_requested = level; |
465 | lockres->l_flags |= USER_LOCK_BUSY; | 481 | lockres->l_flags |= USER_LOCK_BUSY; |
466 | spin_unlock(&lockres->l_lock); | 482 | spin_unlock(&lockres->l_lock); |
467 | 483 | ||
468 | BUG_ON(level == LKM_IVMODE); | 484 | BUG_ON(level == DLM_LOCK_IV); |
469 | BUG_ON(level == LKM_NLMODE); | 485 | BUG_ON(level == DLM_LOCK_NL); |
470 | 486 | ||
471 | /* call dlm_lock to upgrade lock now */ | 487 | /* call dlm_lock to upgrade lock now */ |
472 | status = dlmlock(dlm, | 488 | status = ocfs2_dlm_lock(conn, level, &lockres->l_lksb, |
473 | level, | 489 | local_flags, lockres->l_name, |
474 | &lockres->l_lksb, | 490 | lockres->l_namelen); |
475 | local_flags, | 491 | if (status) { |
476 | lockres->l_name, | 492 | if ((lkm_flags & DLM_LKF_NOQUEUE) && |
477 | lockres->l_namelen, | 493 | (status != -EAGAIN)) |
478 | user_ast, | 494 | user_log_dlm_error("ocfs2_dlm_lock", |
479 | lockres, | 495 | status, lockres); |
480 | user_bast); | ||
481 | if (status != DLM_NORMAL) { | ||
482 | if ((lkm_flags & LKM_NOQUEUE) && | ||
483 | (status == DLM_NOTQUEUED)) | ||
484 | status = -EAGAIN; | ||
485 | else { | ||
486 | user_log_dlm_error("dlmlock", status, lockres); | ||
487 | status = -EINVAL; | ||
488 | } | ||
489 | user_recover_from_dlm_error(lockres); | 496 | user_recover_from_dlm_error(lockres); |
490 | goto bail; | 497 | goto bail; |
491 | } | 498 | } |
@@ -506,11 +513,11 @@ static inline void user_dlm_dec_holders(struct user_lock_res *lockres, | |||
506 | int level) | 513 | int level) |
507 | { | 514 | { |
508 | switch(level) { | 515 | switch(level) { |
509 | case LKM_EXMODE: | 516 | case DLM_LOCK_EX: |
510 | BUG_ON(!lockres->l_ex_holders); | 517 | BUG_ON(!lockres->l_ex_holders); |
511 | lockres->l_ex_holders--; | 518 | lockres->l_ex_holders--; |
512 | break; | 519 | break; |
513 | case LKM_PRMODE: | 520 | case DLM_LOCK_PR: |
514 | BUG_ON(!lockres->l_ro_holders); | 521 | BUG_ON(!lockres->l_ro_holders); |
515 | lockres->l_ro_holders--; | 522 | lockres->l_ro_holders--; |
516 | break; | 523 | break; |
@@ -522,8 +529,8 @@ static inline void user_dlm_dec_holders(struct user_lock_res *lockres, | |||
522 | void user_dlm_cluster_unlock(struct user_lock_res *lockres, | 529 | void user_dlm_cluster_unlock(struct user_lock_res *lockres, |
523 | int level) | 530 | int level) |
524 | { | 531 | { |
525 | if (level != LKM_EXMODE && | 532 | if (level != DLM_LOCK_EX && |
526 | level != LKM_PRMODE) { | 533 | level != DLM_LOCK_PR) { |
527 | mlog(ML_ERROR, "lockres %.*s: invalid request!\n", | 534 | mlog(ML_ERROR, "lockres %.*s: invalid request!\n", |
528 | lockres->l_namelen, lockres->l_name); | 535 | lockres->l_namelen, lockres->l_name); |
529 | return; | 536 | return; |
@@ -540,33 +547,40 @@ void user_dlm_write_lvb(struct inode *inode, | |||
540 | unsigned int len) | 547 | unsigned int len) |
541 | { | 548 | { |
542 | struct user_lock_res *lockres = &DLMFS_I(inode)->ip_lockres; | 549 | struct user_lock_res *lockres = &DLMFS_I(inode)->ip_lockres; |
543 | char *lvb = lockres->l_lksb.lvb; | 550 | char *lvb; |
544 | 551 | ||
545 | BUG_ON(len > DLM_LVB_LEN); | 552 | BUG_ON(len > DLM_LVB_LEN); |
546 | 553 | ||
547 | spin_lock(&lockres->l_lock); | 554 | spin_lock(&lockres->l_lock); |
548 | 555 | ||
549 | BUG_ON(lockres->l_level < LKM_EXMODE); | 556 | BUG_ON(lockres->l_level < DLM_LOCK_EX); |
557 | lvb = ocfs2_dlm_lvb(&lockres->l_lksb); | ||
550 | memcpy(lvb, val, len); | 558 | memcpy(lvb, val, len); |
551 | 559 | ||
552 | spin_unlock(&lockres->l_lock); | 560 | spin_unlock(&lockres->l_lock); |
553 | } | 561 | } |
554 | 562 | ||
555 | void user_dlm_read_lvb(struct inode *inode, | 563 | ssize_t user_dlm_read_lvb(struct inode *inode, |
556 | char *val, | 564 | char *val, |
557 | unsigned int len) | 565 | unsigned int len) |
558 | { | 566 | { |
559 | struct user_lock_res *lockres = &DLMFS_I(inode)->ip_lockres; | 567 | struct user_lock_res *lockres = &DLMFS_I(inode)->ip_lockres; |
560 | char *lvb = lockres->l_lksb.lvb; | 568 | char *lvb; |
569 | ssize_t ret = len; | ||
561 | 570 | ||
562 | BUG_ON(len > DLM_LVB_LEN); | 571 | BUG_ON(len > DLM_LVB_LEN); |
563 | 572 | ||
564 | spin_lock(&lockres->l_lock); | 573 | spin_lock(&lockres->l_lock); |
565 | 574 | ||
566 | BUG_ON(lockres->l_level < LKM_PRMODE); | 575 | BUG_ON(lockres->l_level < DLM_LOCK_PR); |
567 | memcpy(val, lvb, len); | 576 | if (ocfs2_dlm_lvb_valid(&lockres->l_lksb)) { |
577 | lvb = ocfs2_dlm_lvb(&lockres->l_lksb); | ||
578 | memcpy(val, lvb, len); | ||
579 | } else | ||
580 | ret = 0; | ||
568 | 581 | ||
569 | spin_unlock(&lockres->l_lock); | 582 | spin_unlock(&lockres->l_lock); |
583 | return ret; | ||
570 | } | 584 | } |
571 | 585 | ||
572 | void user_dlm_lock_res_init(struct user_lock_res *lockres, | 586 | void user_dlm_lock_res_init(struct user_lock_res *lockres, |
@@ -576,9 +590,9 @@ void user_dlm_lock_res_init(struct user_lock_res *lockres, | |||
576 | 590 | ||
577 | spin_lock_init(&lockres->l_lock); | 591 | spin_lock_init(&lockres->l_lock); |
578 | init_waitqueue_head(&lockres->l_event); | 592 | init_waitqueue_head(&lockres->l_event); |
579 | lockres->l_level = LKM_IVMODE; | 593 | lockres->l_level = DLM_LOCK_IV; |
580 | lockres->l_requested = LKM_IVMODE; | 594 | lockres->l_requested = DLM_LOCK_IV; |
581 | lockres->l_blocking = LKM_IVMODE; | 595 | lockres->l_blocking = DLM_LOCK_IV; |
582 | 596 | ||
583 | /* should have been checked before getting here. */ | 597 | /* should have been checked before getting here. */ |
584 | BUG_ON(dentry->d_name.len >= USER_DLM_LOCK_ID_MAX_LEN); | 598 | BUG_ON(dentry->d_name.len >= USER_DLM_LOCK_ID_MAX_LEN); |
@@ -592,9 +606,10 @@ void user_dlm_lock_res_init(struct user_lock_res *lockres, | |||
592 | int user_dlm_destroy_lock(struct user_lock_res *lockres) | 606 | int user_dlm_destroy_lock(struct user_lock_res *lockres) |
593 | { | 607 | { |
594 | int status = -EBUSY; | 608 | int status = -EBUSY; |
595 | struct dlm_ctxt *dlm = dlm_ctxt_from_user_lockres(lockres); | 609 | struct ocfs2_cluster_connection *conn = |
610 | cluster_connection_from_user_lockres(lockres); | ||
596 | 611 | ||
597 | mlog(0, "asked to destroy %.*s\n", lockres->l_namelen, lockres->l_name); | 612 | mlog(ML_BASTS, "lockres %.*s\n", lockres->l_namelen, lockres->l_name); |
598 | 613 | ||
599 | spin_lock(&lockres->l_lock); | 614 | spin_lock(&lockres->l_lock); |
600 | if (lockres->l_flags & USER_LOCK_IN_TEARDOWN) { | 615 | if (lockres->l_flags & USER_LOCK_IN_TEARDOWN) { |
@@ -627,14 +642,9 @@ int user_dlm_destroy_lock(struct user_lock_res *lockres) | |||
627 | lockres->l_flags |= USER_LOCK_BUSY; | 642 | lockres->l_flags |= USER_LOCK_BUSY; |
628 | spin_unlock(&lockres->l_lock); | 643 | spin_unlock(&lockres->l_lock); |
629 | 644 | ||
630 | status = dlmunlock(dlm, | 645 | status = ocfs2_dlm_unlock(conn, &lockres->l_lksb, DLM_LKF_VALBLK); |
631 | &lockres->l_lksb, | 646 | if (status) { |
632 | LKM_VALBLK, | 647 | user_log_dlm_error("ocfs2_dlm_unlock", status, lockres); |
633 | user_unlock_ast, | ||
634 | lockres); | ||
635 | if (status != DLM_NORMAL) { | ||
636 | user_log_dlm_error("dlmunlock", status, lockres); | ||
637 | status = -EINVAL; | ||
638 | goto bail; | 648 | goto bail; |
639 | } | 649 | } |
640 | 650 | ||
@@ -645,32 +655,34 @@ bail: | |||
645 | return status; | 655 | return status; |
646 | } | 656 | } |
647 | 657 | ||
648 | struct dlm_ctxt *user_dlm_register_context(struct qstr *name, | 658 | static void user_dlm_recovery_handler_noop(int node_num, |
649 | struct dlm_protocol_version *proto) | 659 | void *recovery_data) |
650 | { | 660 | { |
651 | struct dlm_ctxt *dlm; | 661 | /* We ignore recovery events */ |
652 | u32 dlm_key; | 662 | return; |
653 | char *domain; | 663 | } |
654 | |||
655 | domain = kmalloc(name->len + 1, GFP_NOFS); | ||
656 | if (!domain) { | ||
657 | mlog_errno(-ENOMEM); | ||
658 | return ERR_PTR(-ENOMEM); | ||
659 | } | ||
660 | 664 | ||
661 | dlm_key = crc32_le(0, name->name, name->len); | 665 | void user_dlm_set_locking_protocol(void) |
666 | { | ||
667 | ocfs2_stack_glue_set_max_proto_version(&user_dlm_lproto.lp_max_version); | ||
668 | } | ||
662 | 669 | ||
663 | snprintf(domain, name->len + 1, "%.*s", name->len, name->name); | 670 | struct ocfs2_cluster_connection *user_dlm_register(struct qstr *name) |
671 | { | ||
672 | int rc; | ||
673 | struct ocfs2_cluster_connection *conn; | ||
664 | 674 | ||
665 | dlm = dlm_register_domain(domain, dlm_key, proto); | 675 | rc = ocfs2_cluster_connect_agnostic(name->name, name->len, |
666 | if (IS_ERR(dlm)) | 676 | &user_dlm_lproto, |
667 | mlog_errno(PTR_ERR(dlm)); | 677 | user_dlm_recovery_handler_noop, |
678 | NULL, &conn); | ||
679 | if (rc) | ||
680 | mlog_errno(rc); | ||
668 | 681 | ||
669 | kfree(domain); | 682 | return rc ? ERR_PTR(rc) : conn; |
670 | return dlm; | ||
671 | } | 683 | } |
672 | 684 | ||
673 | void user_dlm_unregister_context(struct dlm_ctxt *dlm) | 685 | void user_dlm_unregister(struct ocfs2_cluster_connection *conn) |
674 | { | 686 | { |
675 | dlm_unregister_domain(dlm); | 687 | ocfs2_cluster_disconnect(conn, 0); |
676 | } | 688 | } |
diff --git a/fs/ocfs2/dlm/userdlm.h b/fs/ocfs2/dlmfs/userdlm.h index 0c3cc03c61fa..3b42d79531d7 100644 --- a/fs/ocfs2/dlm/userdlm.h +++ b/fs/ocfs2/dlmfs/userdlm.h | |||
@@ -57,7 +57,7 @@ struct user_lock_res { | |||
57 | int l_level; | 57 | int l_level; |
58 | unsigned int l_ro_holders; | 58 | unsigned int l_ro_holders; |
59 | unsigned int l_ex_holders; | 59 | unsigned int l_ex_holders; |
60 | struct dlm_lockstatus l_lksb; | 60 | struct ocfs2_dlm_lksb l_lksb; |
61 | 61 | ||
62 | int l_requested; | 62 | int l_requested; |
63 | int l_blocking; | 63 | int l_blocking; |
@@ -80,15 +80,15 @@ void user_dlm_cluster_unlock(struct user_lock_res *lockres, | |||
80 | void user_dlm_write_lvb(struct inode *inode, | 80 | void user_dlm_write_lvb(struct inode *inode, |
81 | const char *val, | 81 | const char *val, |
82 | unsigned int len); | 82 | unsigned int len); |
83 | void user_dlm_read_lvb(struct inode *inode, | 83 | ssize_t user_dlm_read_lvb(struct inode *inode, |
84 | char *val, | 84 | char *val, |
85 | unsigned int len); | 85 | unsigned int len); |
86 | struct dlm_ctxt *user_dlm_register_context(struct qstr *name, | 86 | struct ocfs2_cluster_connection *user_dlm_register(struct qstr *name); |
87 | struct dlm_protocol_version *proto); | 87 | void user_dlm_unregister(struct ocfs2_cluster_connection *conn); |
88 | void user_dlm_unregister_context(struct dlm_ctxt *dlm); | 88 | void user_dlm_set_locking_protocol(void); |
89 | 89 | ||
90 | struct dlmfs_inode_private { | 90 | struct dlmfs_inode_private { |
91 | struct dlm_ctxt *ip_dlm; | 91 | struct ocfs2_cluster_connection *ip_conn; |
92 | 92 | ||
93 | struct user_lock_res ip_lockres; /* unused for directories. */ | 93 | struct user_lock_res ip_lockres; /* unused for directories. */ |
94 | struct inode *ip_parent; | 94 | struct inode *ip_parent; |
diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c index e044019cb3b1..8298608d4165 100644 --- a/fs/ocfs2/dlmglue.c +++ b/fs/ocfs2/dlmglue.c | |||
@@ -297,6 +297,11 @@ static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres) | |||
297 | lockres->l_type == OCFS2_LOCK_TYPE_OPEN; | 297 | lockres->l_type == OCFS2_LOCK_TYPE_OPEN; |
298 | } | 298 | } |
299 | 299 | ||
300 | static inline struct ocfs2_lock_res *ocfs2_lksb_to_lock_res(struct ocfs2_dlm_lksb *lksb) | ||
301 | { | ||
302 | return container_of(lksb, struct ocfs2_lock_res, l_lksb); | ||
303 | } | ||
304 | |||
300 | static inline struct inode *ocfs2_lock_res_inode(struct ocfs2_lock_res *lockres) | 305 | static inline struct inode *ocfs2_lock_res_inode(struct ocfs2_lock_res *lockres) |
301 | { | 306 | { |
302 | BUG_ON(!ocfs2_is_inode_lock(lockres)); | 307 | BUG_ON(!ocfs2_is_inode_lock(lockres)); |
@@ -927,6 +932,10 @@ static int ocfs2_generic_handle_bast(struct ocfs2_lock_res *lockres, | |||
927 | lockres->l_blocking = level; | 932 | lockres->l_blocking = level; |
928 | } | 933 | } |
929 | 934 | ||
935 | mlog(ML_BASTS, "lockres %s, block %d, level %d, l_block %d, dwn %d\n", | ||
936 | lockres->l_name, level, lockres->l_level, lockres->l_blocking, | ||
937 | needs_downconvert); | ||
938 | |||
930 | if (needs_downconvert) | 939 | if (needs_downconvert) |
931 | lockres_or_flags(lockres, OCFS2_LOCK_BLOCKED); | 940 | lockres_or_flags(lockres, OCFS2_LOCK_BLOCKED); |
932 | 941 | ||
@@ -1040,18 +1049,17 @@ static unsigned int lockres_set_pending(struct ocfs2_lock_res *lockres) | |||
1040 | return lockres->l_pending_gen; | 1049 | return lockres->l_pending_gen; |
1041 | } | 1050 | } |
1042 | 1051 | ||
1043 | 1052 | static void ocfs2_blocking_ast(struct ocfs2_dlm_lksb *lksb, int level) | |
1044 | static void ocfs2_blocking_ast(void *opaque, int level) | ||
1045 | { | 1053 | { |
1046 | struct ocfs2_lock_res *lockres = opaque; | 1054 | struct ocfs2_lock_res *lockres = ocfs2_lksb_to_lock_res(lksb); |
1047 | struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres); | 1055 | struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres); |
1048 | int needs_downconvert; | 1056 | int needs_downconvert; |
1049 | unsigned long flags; | 1057 | unsigned long flags; |
1050 | 1058 | ||
1051 | BUG_ON(level <= DLM_LOCK_NL); | 1059 | BUG_ON(level <= DLM_LOCK_NL); |
1052 | 1060 | ||
1053 | mlog(0, "BAST fired for lockres %s, blocking %d, level %d type %s\n", | 1061 | mlog(ML_BASTS, "BAST fired for lockres %s, blocking %d, level %d, " |
1054 | lockres->l_name, level, lockres->l_level, | 1062 | "type %s\n", lockres->l_name, level, lockres->l_level, |
1055 | ocfs2_lock_type_string(lockres->l_type)); | 1063 | ocfs2_lock_type_string(lockres->l_type)); |
1056 | 1064 | ||
1057 | /* | 1065 | /* |
@@ -1072,9 +1080,9 @@ static void ocfs2_blocking_ast(void *opaque, int level) | |||
1072 | ocfs2_wake_downconvert_thread(osb); | 1080 | ocfs2_wake_downconvert_thread(osb); |
1073 | } | 1081 | } |
1074 | 1082 | ||
1075 | static void ocfs2_locking_ast(void *opaque) | 1083 | static void ocfs2_locking_ast(struct ocfs2_dlm_lksb *lksb) |
1076 | { | 1084 | { |
1077 | struct ocfs2_lock_res *lockres = opaque; | 1085 | struct ocfs2_lock_res *lockres = ocfs2_lksb_to_lock_res(lksb); |
1078 | struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres); | 1086 | struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres); |
1079 | unsigned long flags; | 1087 | unsigned long flags; |
1080 | int status; | 1088 | int status; |
@@ -1095,6 +1103,10 @@ static void ocfs2_locking_ast(void *opaque) | |||
1095 | return; | 1103 | return; |
1096 | } | 1104 | } |
1097 | 1105 | ||
1106 | mlog(ML_BASTS, "AST fired for lockres %s, action %d, unlock %d, " | ||
1107 | "level %d => %d\n", lockres->l_name, lockres->l_action, | ||
1108 | lockres->l_unlock_action, lockres->l_level, lockres->l_requested); | ||
1109 | |||
1098 | switch(lockres->l_action) { | 1110 | switch(lockres->l_action) { |
1099 | case OCFS2_AST_ATTACH: | 1111 | case OCFS2_AST_ATTACH: |
1100 | ocfs2_generic_handle_attach_action(lockres); | 1112 | ocfs2_generic_handle_attach_action(lockres); |
@@ -1107,8 +1119,8 @@ static void ocfs2_locking_ast(void *opaque) | |||
1107 | ocfs2_generic_handle_downconvert_action(lockres); | 1119 | ocfs2_generic_handle_downconvert_action(lockres); |
1108 | break; | 1120 | break; |
1109 | default: | 1121 | default: |
1110 | mlog(ML_ERROR, "lockres %s: ast fired with invalid action: %u " | 1122 | mlog(ML_ERROR, "lockres %s: AST fired with invalid action: %u, " |
1111 | "lockres flags = 0x%lx, unlock action: %u\n", | 1123 | "flags 0x%lx, unlock: %u\n", |
1112 | lockres->l_name, lockres->l_action, lockres->l_flags, | 1124 | lockres->l_name, lockres->l_action, lockres->l_flags, |
1113 | lockres->l_unlock_action); | 1125 | lockres->l_unlock_action); |
1114 | BUG(); | 1126 | BUG(); |
@@ -1134,6 +1146,88 @@ out: | |||
1134 | spin_unlock_irqrestore(&lockres->l_lock, flags); | 1146 | spin_unlock_irqrestore(&lockres->l_lock, flags); |
1135 | } | 1147 | } |
1136 | 1148 | ||
1149 | static void ocfs2_unlock_ast(struct ocfs2_dlm_lksb *lksb, int error) | ||
1150 | { | ||
1151 | struct ocfs2_lock_res *lockres = ocfs2_lksb_to_lock_res(lksb); | ||
1152 | unsigned long flags; | ||
1153 | |||
1154 | mlog_entry_void(); | ||
1155 | |||
1156 | mlog(ML_BASTS, "UNLOCK AST fired for lockres %s, action = %d\n", | ||
1157 | lockres->l_name, lockres->l_unlock_action); | ||
1158 | |||
1159 | spin_lock_irqsave(&lockres->l_lock, flags); | ||
1160 | if (error) { | ||
1161 | mlog(ML_ERROR, "Dlm passes error %d for lock %s, " | ||
1162 | "unlock_action %d\n", error, lockres->l_name, | ||
1163 | lockres->l_unlock_action); | ||
1164 | spin_unlock_irqrestore(&lockres->l_lock, flags); | ||
1165 | mlog_exit_void(); | ||
1166 | return; | ||
1167 | } | ||
1168 | |||
1169 | switch(lockres->l_unlock_action) { | ||
1170 | case OCFS2_UNLOCK_CANCEL_CONVERT: | ||
1171 | mlog(0, "Cancel convert success for %s\n", lockres->l_name); | ||
1172 | lockres->l_action = OCFS2_AST_INVALID; | ||
1173 | /* Downconvert thread may have requeued this lock, we | ||
1174 | * need to wake it. */ | ||
1175 | if (lockres->l_flags & OCFS2_LOCK_BLOCKED) | ||
1176 | ocfs2_wake_downconvert_thread(ocfs2_get_lockres_osb(lockres)); | ||
1177 | break; | ||
1178 | case OCFS2_UNLOCK_DROP_LOCK: | ||
1179 | lockres->l_level = DLM_LOCK_IV; | ||
1180 | break; | ||
1181 | default: | ||
1182 | BUG(); | ||
1183 | } | ||
1184 | |||
1185 | lockres_clear_flags(lockres, OCFS2_LOCK_BUSY); | ||
1186 | lockres->l_unlock_action = OCFS2_UNLOCK_INVALID; | ||
1187 | wake_up(&lockres->l_event); | ||
1188 | spin_unlock_irqrestore(&lockres->l_lock, flags); | ||
1189 | |||
1190 | mlog_exit_void(); | ||
1191 | } | ||
1192 | |||
1193 | /* | ||
1194 | * This is the filesystem locking protocol. It provides the lock handling | ||
1195 | * hooks for the underlying DLM. It has a maximum version number. | ||
1196 | * The version number allows interoperability with systems running at | ||
1197 | * the same major number and an equal or smaller minor number. | ||
1198 | * | ||
1199 | * Whenever the filesystem does new things with locks (adds or removes a | ||
1200 | * lock, orders them differently, does different things underneath a lock), | ||
1201 | * the version must be changed. The protocol is negotiated when joining | ||
1202 | * the dlm domain. A node may join the domain if its major version is | ||
1203 | * identical to all other nodes and its minor version is greater than | ||
1204 | * or equal to all other nodes. When its minor version is greater than | ||
1205 | * the other nodes, it will run at the minor version specified by the | ||
1206 | * other nodes. | ||
1207 | * | ||
1208 | * If a locking change is made that will not be compatible with older | ||
1209 | * versions, the major number must be increased and the minor version set | ||
1210 | * to zero. If a change merely adds a behavior that can be disabled when | ||
1211 | * speaking to older versions, the minor version must be increased. If a | ||
1212 | * change adds a fully backwards compatible change (eg, LVB changes that | ||
1213 | * are just ignored by older versions), the version does not need to be | ||
1214 | * updated. | ||
1215 | */ | ||
1216 | static struct ocfs2_locking_protocol lproto = { | ||
1217 | .lp_max_version = { | ||
1218 | .pv_major = OCFS2_LOCKING_PROTOCOL_MAJOR, | ||
1219 | .pv_minor = OCFS2_LOCKING_PROTOCOL_MINOR, | ||
1220 | }, | ||
1221 | .lp_lock_ast = ocfs2_locking_ast, | ||
1222 | .lp_blocking_ast = ocfs2_blocking_ast, | ||
1223 | .lp_unlock_ast = ocfs2_unlock_ast, | ||
1224 | }; | ||
1225 | |||
1226 | void ocfs2_set_locking_protocol(void) | ||
1227 | { | ||
1228 | ocfs2_stack_glue_set_max_proto_version(&lproto.lp_max_version); | ||
1229 | } | ||
1230 | |||
1137 | static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres, | 1231 | static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres, |
1138 | int convert) | 1232 | int convert) |
1139 | { | 1233 | { |
@@ -1189,8 +1283,7 @@ static int ocfs2_lock_create(struct ocfs2_super *osb, | |||
1189 | &lockres->l_lksb, | 1283 | &lockres->l_lksb, |
1190 | dlm_flags, | 1284 | dlm_flags, |
1191 | lockres->l_name, | 1285 | lockres->l_name, |
1192 | OCFS2_LOCK_ID_MAX_LEN - 1, | 1286 | OCFS2_LOCK_ID_MAX_LEN - 1); |
1193 | lockres); | ||
1194 | lockres_clear_pending(lockres, gen, osb); | 1287 | lockres_clear_pending(lockres, gen, osb); |
1195 | if (ret) { | 1288 | if (ret) { |
1196 | ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres); | 1289 | ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres); |
@@ -1412,7 +1505,7 @@ again: | |||
1412 | BUG_ON(level == DLM_LOCK_IV); | 1505 | BUG_ON(level == DLM_LOCK_IV); |
1413 | BUG_ON(level == DLM_LOCK_NL); | 1506 | BUG_ON(level == DLM_LOCK_NL); |
1414 | 1507 | ||
1415 | mlog(0, "lock %s, convert from %d to level = %d\n", | 1508 | mlog(ML_BASTS, "lockres %s, convert from %d to %d\n", |
1416 | lockres->l_name, lockres->l_level, level); | 1509 | lockres->l_name, lockres->l_level, level); |
1417 | 1510 | ||
1418 | /* call dlm_lock to upgrade lock now */ | 1511 | /* call dlm_lock to upgrade lock now */ |
@@ -1421,8 +1514,7 @@ again: | |||
1421 | &lockres->l_lksb, | 1514 | &lockres->l_lksb, |
1422 | lkm_flags, | 1515 | lkm_flags, |
1423 | lockres->l_name, | 1516 | lockres->l_name, |
1424 | OCFS2_LOCK_ID_MAX_LEN - 1, | 1517 | OCFS2_LOCK_ID_MAX_LEN - 1); |
1425 | lockres); | ||
1426 | lockres_clear_pending(lockres, gen, osb); | 1518 | lockres_clear_pending(lockres, gen, osb); |
1427 | if (ret) { | 1519 | if (ret) { |
1428 | if (!(lkm_flags & DLM_LKF_NOQUEUE) || | 1520 | if (!(lkm_flags & DLM_LKF_NOQUEUE) || |
@@ -1859,8 +1951,7 @@ int ocfs2_file_lock(struct file *file, int ex, int trylock) | |||
1859 | spin_unlock_irqrestore(&lockres->l_lock, flags); | 1951 | spin_unlock_irqrestore(&lockres->l_lock, flags); |
1860 | 1952 | ||
1861 | ret = ocfs2_dlm_lock(osb->cconn, level, &lockres->l_lksb, lkm_flags, | 1953 | ret = ocfs2_dlm_lock(osb->cconn, level, &lockres->l_lksb, lkm_flags, |
1862 | lockres->l_name, OCFS2_LOCK_ID_MAX_LEN - 1, | 1954 | lockres->l_name, OCFS2_LOCK_ID_MAX_LEN - 1); |
1863 | lockres); | ||
1864 | if (ret) { | 1955 | if (ret) { |
1865 | if (!trylock || (ret != -EAGAIN)) { | 1956 | if (!trylock || (ret != -EAGAIN)) { |
1866 | ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres); | 1957 | ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres); |
@@ -2989,7 +3080,7 @@ int ocfs2_dlm_init(struct ocfs2_super *osb) | |||
2989 | status = ocfs2_cluster_connect(osb->osb_cluster_stack, | 3080 | status = ocfs2_cluster_connect(osb->osb_cluster_stack, |
2990 | osb->uuid_str, | 3081 | osb->uuid_str, |
2991 | strlen(osb->uuid_str), | 3082 | strlen(osb->uuid_str), |
2992 | ocfs2_do_node_down, osb, | 3083 | &lproto, ocfs2_do_node_down, osb, |
2993 | &conn); | 3084 | &conn); |
2994 | if (status) { | 3085 | if (status) { |
2995 | mlog_errno(status); | 3086 | mlog_errno(status); |
@@ -3056,50 +3147,6 @@ void ocfs2_dlm_shutdown(struct ocfs2_super *osb, | |||
3056 | mlog_exit_void(); | 3147 | mlog_exit_void(); |
3057 | } | 3148 | } |
3058 | 3149 | ||
3059 | static void ocfs2_unlock_ast(void *opaque, int error) | ||
3060 | { | ||
3061 | struct ocfs2_lock_res *lockres = opaque; | ||
3062 | unsigned long flags; | ||
3063 | |||
3064 | mlog_entry_void(); | ||
3065 | |||
3066 | mlog(0, "UNLOCK AST called on lock %s, action = %d\n", lockres->l_name, | ||
3067 | lockres->l_unlock_action); | ||
3068 | |||
3069 | spin_lock_irqsave(&lockres->l_lock, flags); | ||
3070 | if (error) { | ||
3071 | mlog(ML_ERROR, "Dlm passes error %d for lock %s, " | ||
3072 | "unlock_action %d\n", error, lockres->l_name, | ||
3073 | lockres->l_unlock_action); | ||
3074 | spin_unlock_irqrestore(&lockres->l_lock, flags); | ||
3075 | mlog_exit_void(); | ||
3076 | return; | ||
3077 | } | ||
3078 | |||
3079 | switch(lockres->l_unlock_action) { | ||
3080 | case OCFS2_UNLOCK_CANCEL_CONVERT: | ||
3081 | mlog(0, "Cancel convert success for %s\n", lockres->l_name); | ||
3082 | lockres->l_action = OCFS2_AST_INVALID; | ||
3083 | /* Downconvert thread may have requeued this lock, we | ||
3084 | * need to wake it. */ | ||
3085 | if (lockres->l_flags & OCFS2_LOCK_BLOCKED) | ||
3086 | ocfs2_wake_downconvert_thread(ocfs2_get_lockres_osb(lockres)); | ||
3087 | break; | ||
3088 | case OCFS2_UNLOCK_DROP_LOCK: | ||
3089 | lockres->l_level = DLM_LOCK_IV; | ||
3090 | break; | ||
3091 | default: | ||
3092 | BUG(); | ||
3093 | } | ||
3094 | |||
3095 | lockres_clear_flags(lockres, OCFS2_LOCK_BUSY); | ||
3096 | lockres->l_unlock_action = OCFS2_UNLOCK_INVALID; | ||
3097 | wake_up(&lockres->l_event); | ||
3098 | spin_unlock_irqrestore(&lockres->l_lock, flags); | ||
3099 | |||
3100 | mlog_exit_void(); | ||
3101 | } | ||
3102 | |||
3103 | static int ocfs2_drop_lock(struct ocfs2_super *osb, | 3150 | static int ocfs2_drop_lock(struct ocfs2_super *osb, |
3104 | struct ocfs2_lock_res *lockres) | 3151 | struct ocfs2_lock_res *lockres) |
3105 | { | 3152 | { |
@@ -3167,8 +3214,7 @@ static int ocfs2_drop_lock(struct ocfs2_super *osb, | |||
3167 | 3214 | ||
3168 | mlog(0, "lock %s\n", lockres->l_name); | 3215 | mlog(0, "lock %s\n", lockres->l_name); |
3169 | 3216 | ||
3170 | ret = ocfs2_dlm_unlock(osb->cconn, &lockres->l_lksb, lkm_flags, | 3217 | ret = ocfs2_dlm_unlock(osb->cconn, &lockres->l_lksb, lkm_flags); |
3171 | lockres); | ||
3172 | if (ret) { | 3218 | if (ret) { |
3173 | ocfs2_log_dlm_error("ocfs2_dlm_unlock", ret, lockres); | 3219 | ocfs2_log_dlm_error("ocfs2_dlm_unlock", ret, lockres); |
3174 | mlog(ML_ERROR, "lockres flags: %lu\n", lockres->l_flags); | 3220 | mlog(ML_ERROR, "lockres flags: %lu\n", lockres->l_flags); |
@@ -3276,13 +3322,20 @@ static unsigned int ocfs2_prepare_downconvert(struct ocfs2_lock_res *lockres, | |||
3276 | BUG_ON(lockres->l_blocking <= DLM_LOCK_NL); | 3322 | BUG_ON(lockres->l_blocking <= DLM_LOCK_NL); |
3277 | 3323 | ||
3278 | if (lockres->l_level <= new_level) { | 3324 | if (lockres->l_level <= new_level) { |
3279 | mlog(ML_ERROR, "lockres->l_level (%d) <= new_level (%d)\n", | 3325 | mlog(ML_ERROR, "lockres %s, lvl %d <= %d, blcklst %d, mask %d, " |
3280 | lockres->l_level, new_level); | 3326 | "type %d, flags 0x%lx, hold %d %d, act %d %d, req %d, " |
3327 | "block %d, pgen %d\n", lockres->l_name, lockres->l_level, | ||
3328 | new_level, list_empty(&lockres->l_blocked_list), | ||
3329 | list_empty(&lockres->l_mask_waiters), lockres->l_type, | ||
3330 | lockres->l_flags, lockres->l_ro_holders, | ||
3331 | lockres->l_ex_holders, lockres->l_action, | ||
3332 | lockres->l_unlock_action, lockres->l_requested, | ||
3333 | lockres->l_blocking, lockres->l_pending_gen); | ||
3281 | BUG(); | 3334 | BUG(); |
3282 | } | 3335 | } |
3283 | 3336 | ||
3284 | mlog(0, "lock %s, new_level = %d, l_blocking = %d\n", | 3337 | mlog(ML_BASTS, "lockres %s, level %d => %d, blocking %d\n", |
3285 | lockres->l_name, new_level, lockres->l_blocking); | 3338 | lockres->l_name, lockres->l_level, new_level, lockres->l_blocking); |
3286 | 3339 | ||
3287 | lockres->l_action = OCFS2_AST_DOWNCONVERT; | 3340 | lockres->l_action = OCFS2_AST_DOWNCONVERT; |
3288 | lockres->l_requested = new_level; | 3341 | lockres->l_requested = new_level; |
@@ -3301,6 +3354,9 @@ static int ocfs2_downconvert_lock(struct ocfs2_super *osb, | |||
3301 | 3354 | ||
3302 | mlog_entry_void(); | 3355 | mlog_entry_void(); |
3303 | 3356 | ||
3357 | mlog(ML_BASTS, "lockres %s, level %d => %d\n", lockres->l_name, | ||
3358 | lockres->l_level, new_level); | ||
3359 | |||
3304 | if (lvb) | 3360 | if (lvb) |
3305 | dlm_flags |= DLM_LKF_VALBLK; | 3361 | dlm_flags |= DLM_LKF_VALBLK; |
3306 | 3362 | ||
@@ -3309,8 +3365,7 @@ static int ocfs2_downconvert_lock(struct ocfs2_super *osb, | |||
3309 | &lockres->l_lksb, | 3365 | &lockres->l_lksb, |
3310 | dlm_flags, | 3366 | dlm_flags, |
3311 | lockres->l_name, | 3367 | lockres->l_name, |
3312 | OCFS2_LOCK_ID_MAX_LEN - 1, | 3368 | OCFS2_LOCK_ID_MAX_LEN - 1); |
3313 | lockres); | ||
3314 | lockres_clear_pending(lockres, generation, osb); | 3369 | lockres_clear_pending(lockres, generation, osb); |
3315 | if (ret) { | 3370 | if (ret) { |
3316 | ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres); | 3371 | ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres); |
@@ -3331,14 +3386,12 @@ static int ocfs2_prepare_cancel_convert(struct ocfs2_super *osb, | |||
3331 | assert_spin_locked(&lockres->l_lock); | 3386 | assert_spin_locked(&lockres->l_lock); |
3332 | 3387 | ||
3333 | mlog_entry_void(); | 3388 | mlog_entry_void(); |
3334 | mlog(0, "lock %s\n", lockres->l_name); | ||
3335 | 3389 | ||
3336 | if (lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) { | 3390 | if (lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) { |
3337 | /* If we're already trying to cancel a lock conversion | 3391 | /* If we're already trying to cancel a lock conversion |
3338 | * then just drop the spinlock and allow the caller to | 3392 | * then just drop the spinlock and allow the caller to |
3339 | * requeue this lock. */ | 3393 | * requeue this lock. */ |
3340 | 3394 | mlog(ML_BASTS, "lockres %s, skip convert\n", lockres->l_name); | |
3341 | mlog(0, "Lockres %s, skip convert\n", lockres->l_name); | ||
3342 | return 0; | 3395 | return 0; |
3343 | } | 3396 | } |
3344 | 3397 | ||
@@ -3353,6 +3406,8 @@ static int ocfs2_prepare_cancel_convert(struct ocfs2_super *osb, | |||
3353 | "lock %s, invalid flags: 0x%lx\n", | 3406 | "lock %s, invalid flags: 0x%lx\n", |
3354 | lockres->l_name, lockres->l_flags); | 3407 | lockres->l_name, lockres->l_flags); |
3355 | 3408 | ||
3409 | mlog(ML_BASTS, "lockres %s\n", lockres->l_name); | ||
3410 | |||
3356 | return 1; | 3411 | return 1; |
3357 | } | 3412 | } |
3358 | 3413 | ||
@@ -3362,16 +3417,15 @@ static int ocfs2_cancel_convert(struct ocfs2_super *osb, | |||
3362 | int ret; | 3417 | int ret; |
3363 | 3418 | ||
3364 | mlog_entry_void(); | 3419 | mlog_entry_void(); |
3365 | mlog(0, "lock %s\n", lockres->l_name); | ||
3366 | 3420 | ||
3367 | ret = ocfs2_dlm_unlock(osb->cconn, &lockres->l_lksb, | 3421 | ret = ocfs2_dlm_unlock(osb->cconn, &lockres->l_lksb, |
3368 | DLM_LKF_CANCEL, lockres); | 3422 | DLM_LKF_CANCEL); |
3369 | if (ret) { | 3423 | if (ret) { |
3370 | ocfs2_log_dlm_error("ocfs2_dlm_unlock", ret, lockres); | 3424 | ocfs2_log_dlm_error("ocfs2_dlm_unlock", ret, lockres); |
3371 | ocfs2_recover_from_dlm_error(lockres, 0); | 3425 | ocfs2_recover_from_dlm_error(lockres, 0); |
3372 | } | 3426 | } |
3373 | 3427 | ||
3374 | mlog(0, "lock %s return from ocfs2_dlm_unlock\n", lockres->l_name); | 3428 | mlog(ML_BASTS, "lockres %s\n", lockres->l_name); |
3375 | 3429 | ||
3376 | mlog_exit(ret); | 3430 | mlog_exit(ret); |
3377 | return ret; | 3431 | return ret; |
@@ -3428,8 +3482,11 @@ recheck: | |||
3428 | * at the same time they set OCFS2_DLM_BUSY. They must | 3482 | * at the same time they set OCFS2_DLM_BUSY. They must |
3429 | * clear OCFS2_DLM_PENDING after dlm_lock() returns. | 3483 | * clear OCFS2_DLM_PENDING after dlm_lock() returns. |
3430 | */ | 3484 | */ |
3431 | if (lockres->l_flags & OCFS2_LOCK_PENDING) | 3485 | if (lockres->l_flags & OCFS2_LOCK_PENDING) { |
3486 | mlog(ML_BASTS, "lockres %s, ReQ: Pending\n", | ||
3487 | lockres->l_name); | ||
3432 | goto leave_requeue; | 3488 | goto leave_requeue; |
3489 | } | ||
3433 | 3490 | ||
3434 | ctl->requeue = 1; | 3491 | ctl->requeue = 1; |
3435 | ret = ocfs2_prepare_cancel_convert(osb, lockres); | 3492 | ret = ocfs2_prepare_cancel_convert(osb, lockres); |
@@ -3461,6 +3518,7 @@ recheck: | |||
3461 | */ | 3518 | */ |
3462 | if (lockres->l_level == DLM_LOCK_NL) { | 3519 | if (lockres->l_level == DLM_LOCK_NL) { |
3463 | BUG_ON(lockres->l_ex_holders || lockres->l_ro_holders); | 3520 | BUG_ON(lockres->l_ex_holders || lockres->l_ro_holders); |
3521 | mlog(ML_BASTS, "lockres %s, Aborting dc\n", lockres->l_name); | ||
3464 | lockres->l_blocking = DLM_LOCK_NL; | 3522 | lockres->l_blocking = DLM_LOCK_NL; |
3465 | lockres_clear_flags(lockres, OCFS2_LOCK_BLOCKED); | 3523 | lockres_clear_flags(lockres, OCFS2_LOCK_BLOCKED); |
3466 | spin_unlock_irqrestore(&lockres->l_lock, flags); | 3524 | spin_unlock_irqrestore(&lockres->l_lock, flags); |
@@ -3470,28 +3528,41 @@ recheck: | |||
3470 | /* if we're blocking an exclusive and we have *any* holders, | 3528 | /* if we're blocking an exclusive and we have *any* holders, |
3471 | * then requeue. */ | 3529 | * then requeue. */ |
3472 | if ((lockres->l_blocking == DLM_LOCK_EX) | 3530 | if ((lockres->l_blocking == DLM_LOCK_EX) |
3473 | && (lockres->l_ex_holders || lockres->l_ro_holders)) | 3531 | && (lockres->l_ex_holders || lockres->l_ro_holders)) { |
3532 | mlog(ML_BASTS, "lockres %s, ReQ: EX/PR Holders %u,%u\n", | ||
3533 | lockres->l_name, lockres->l_ex_holders, | ||
3534 | lockres->l_ro_holders); | ||
3474 | goto leave_requeue; | 3535 | goto leave_requeue; |
3536 | } | ||
3475 | 3537 | ||
3476 | /* If it's a PR we're blocking, then only | 3538 | /* If it's a PR we're blocking, then only |
3477 | * requeue if we've got any EX holders */ | 3539 | * requeue if we've got any EX holders */ |
3478 | if (lockres->l_blocking == DLM_LOCK_PR && | 3540 | if (lockres->l_blocking == DLM_LOCK_PR && |
3479 | lockres->l_ex_holders) | 3541 | lockres->l_ex_holders) { |
3542 | mlog(ML_BASTS, "lockres %s, ReQ: EX Holders %u\n", | ||
3543 | lockres->l_name, lockres->l_ex_holders); | ||
3480 | goto leave_requeue; | 3544 | goto leave_requeue; |
3545 | } | ||
3481 | 3546 | ||
3482 | /* | 3547 | /* |
3483 | * Can we get a lock in this state if the holder counts are | 3548 | * Can we get a lock in this state if the holder counts are |
3484 | * zero? The meta data unblock code used to check this. | 3549 | * zero? The meta data unblock code used to check this. |
3485 | */ | 3550 | */ |
3486 | if ((lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH) | 3551 | if ((lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH) |
3487 | && (lockres->l_flags & OCFS2_LOCK_REFRESHING)) | 3552 | && (lockres->l_flags & OCFS2_LOCK_REFRESHING)) { |
3553 | mlog(ML_BASTS, "lockres %s, ReQ: Lock Refreshing\n", | ||
3554 | lockres->l_name); | ||
3488 | goto leave_requeue; | 3555 | goto leave_requeue; |
3556 | } | ||
3489 | 3557 | ||
3490 | new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking); | 3558 | new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking); |
3491 | 3559 | ||
3492 | if (lockres->l_ops->check_downconvert | 3560 | if (lockres->l_ops->check_downconvert |
3493 | && !lockres->l_ops->check_downconvert(lockres, new_level)) | 3561 | && !lockres->l_ops->check_downconvert(lockres, new_level)) { |
3562 | mlog(ML_BASTS, "lockres %s, ReQ: Checkpointing\n", | ||
3563 | lockres->l_name); | ||
3494 | goto leave_requeue; | 3564 | goto leave_requeue; |
3565 | } | ||
3495 | 3566 | ||
3496 | /* If we get here, then we know that there are no more | 3567 | /* If we get here, then we know that there are no more |
3497 | * incompatible holders (and anyone asking for an incompatible | 3568 | * incompatible holders (and anyone asking for an incompatible |
@@ -3509,13 +3580,19 @@ recheck: | |||
3509 | 3580 | ||
3510 | ctl->unblock_action = lockres->l_ops->downconvert_worker(lockres, blocking); | 3581 | ctl->unblock_action = lockres->l_ops->downconvert_worker(lockres, blocking); |
3511 | 3582 | ||
3512 | if (ctl->unblock_action == UNBLOCK_STOP_POST) | 3583 | if (ctl->unblock_action == UNBLOCK_STOP_POST) { |
3584 | mlog(ML_BASTS, "lockres %s, UNBLOCK_STOP_POST\n", | ||
3585 | lockres->l_name); | ||
3513 | goto leave; | 3586 | goto leave; |
3587 | } | ||
3514 | 3588 | ||
3515 | spin_lock_irqsave(&lockres->l_lock, flags); | 3589 | spin_lock_irqsave(&lockres->l_lock, flags); |
3516 | if ((blocking != lockres->l_blocking) || (level != lockres->l_level)) { | 3590 | if ((blocking != lockres->l_blocking) || (level != lockres->l_level)) { |
3517 | /* If this changed underneath us, then we can't drop | 3591 | /* If this changed underneath us, then we can't drop |
3518 | * it just yet. */ | 3592 | * it just yet. */ |
3593 | mlog(ML_BASTS, "lockres %s, block=%d:%d, level=%d:%d, " | ||
3594 | "Recheck\n", lockres->l_name, blocking, | ||
3595 | lockres->l_blocking, level, lockres->l_level); | ||
3519 | goto recheck; | 3596 | goto recheck; |
3520 | } | 3597 | } |
3521 | 3598 | ||
@@ -3910,45 +3987,6 @@ void ocfs2_refcount_unlock(struct ocfs2_refcount_tree *ref_tree, int ex) | |||
3910 | ocfs2_cluster_unlock(osb, lockres, level); | 3987 | ocfs2_cluster_unlock(osb, lockres, level); |
3911 | } | 3988 | } |
3912 | 3989 | ||
3913 | /* | ||
3914 | * This is the filesystem locking protocol. It provides the lock handling | ||
3915 | * hooks for the underlying DLM. It has a maximum version number. | ||
3916 | * The version number allows interoperability with systems running at | ||
3917 | * the same major number and an equal or smaller minor number. | ||
3918 | * | ||
3919 | * Whenever the filesystem does new things with locks (adds or removes a | ||
3920 | * lock, orders them differently, does different things underneath a lock), | ||
3921 | * the version must be changed. The protocol is negotiated when joining | ||
3922 | * the dlm domain. A node may join the domain if its major version is | ||
3923 | * identical to all other nodes and its minor version is greater than | ||
3924 | * or equal to all other nodes. When its minor version is greater than | ||
3925 | * the other nodes, it will run at the minor version specified by the | ||
3926 | * other nodes. | ||
3927 | * | ||
3928 | * If a locking change is made that will not be compatible with older | ||
3929 | * versions, the major number must be increased and the minor version set | ||
3930 | * to zero. If a change merely adds a behavior that can be disabled when | ||
3931 | * speaking to older versions, the minor version must be increased. If a | ||
3932 | * change adds a fully backwards compatible change (eg, LVB changes that | ||
3933 | * are just ignored by older versions), the version does not need to be | ||
3934 | * updated. | ||
3935 | */ | ||
3936 | static struct ocfs2_locking_protocol lproto = { | ||
3937 | .lp_max_version = { | ||
3938 | .pv_major = OCFS2_LOCKING_PROTOCOL_MAJOR, | ||
3939 | .pv_minor = OCFS2_LOCKING_PROTOCOL_MINOR, | ||
3940 | }, | ||
3941 | .lp_lock_ast = ocfs2_locking_ast, | ||
3942 | .lp_blocking_ast = ocfs2_blocking_ast, | ||
3943 | .lp_unlock_ast = ocfs2_unlock_ast, | ||
3944 | }; | ||
3945 | |||
3946 | void ocfs2_set_locking_protocol(void) | ||
3947 | { | ||
3948 | ocfs2_stack_glue_set_locking_protocol(&lproto); | ||
3949 | } | ||
3950 | |||
3951 | |||
3952 | static void ocfs2_process_blocked_lock(struct ocfs2_super *osb, | 3990 | static void ocfs2_process_blocked_lock(struct ocfs2_super *osb, |
3953 | struct ocfs2_lock_res *lockres) | 3991 | struct ocfs2_lock_res *lockres) |
3954 | { | 3992 | { |
@@ -3965,7 +4003,7 @@ static void ocfs2_process_blocked_lock(struct ocfs2_super *osb, | |||
3965 | BUG_ON(!lockres); | 4003 | BUG_ON(!lockres); |
3966 | BUG_ON(!lockres->l_ops); | 4004 | BUG_ON(!lockres->l_ops); |
3967 | 4005 | ||
3968 | mlog(0, "lockres %s blocked.\n", lockres->l_name); | 4006 | mlog(ML_BASTS, "lockres %s blocked\n", lockres->l_name); |
3969 | 4007 | ||
3970 | /* Detect whether a lock has been marked as going away while | 4008 | /* Detect whether a lock has been marked as going away while |
3971 | * the downconvert thread was processing other things. A lock can | 4009 | * the downconvert thread was processing other things. A lock can |
@@ -3988,7 +4026,7 @@ unqueue: | |||
3988 | } else | 4026 | } else |
3989 | ocfs2_schedule_blocked_lock(osb, lockres); | 4027 | ocfs2_schedule_blocked_lock(osb, lockres); |
3990 | 4028 | ||
3991 | mlog(0, "lockres %s, requeue = %s.\n", lockres->l_name, | 4029 | mlog(ML_BASTS, "lockres %s, requeue = %s.\n", lockres->l_name, |
3992 | ctl.requeue ? "yes" : "no"); | 4030 | ctl.requeue ? "yes" : "no"); |
3993 | spin_unlock_irqrestore(&lockres->l_lock, flags); | 4031 | spin_unlock_irqrestore(&lockres->l_lock, flags); |
3994 | 4032 | ||
@@ -4010,7 +4048,7 @@ static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb, | |||
4010 | /* Do not schedule a lock for downconvert when it's on | 4048 | /* Do not schedule a lock for downconvert when it's on |
4011 | * the way to destruction - any nodes wanting access | 4049 | * the way to destruction - any nodes wanting access |
4012 | * to the resource will get it soon. */ | 4050 | * to the resource will get it soon. */ |
4013 | mlog(0, "Lockres %s won't be scheduled: flags 0x%lx\n", | 4051 | mlog(ML_BASTS, "lockres %s won't be scheduled: flags 0x%lx\n", |
4014 | lockres->l_name, lockres->l_flags); | 4052 | lockres->l_name, lockres->l_flags); |
4015 | return; | 4053 | return; |
4016 | } | 4054 | } |
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 558ce0312421..5b52547d6299 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c | |||
@@ -993,10 +993,9 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr) | |||
993 | } | 993 | } |
994 | 994 | ||
995 | if (size_change && attr->ia_size != i_size_read(inode)) { | 995 | if (size_change && attr->ia_size != i_size_read(inode)) { |
996 | if (attr->ia_size > sb->s_maxbytes) { | 996 | status = inode_newsize_ok(inode, attr->ia_size); |
997 | status = -EFBIG; | 997 | if (status) |
998 | goto bail_unlock; | 998 | goto bail_unlock; |
999 | } | ||
1000 | 999 | ||
1001 | if (i_size_read(inode) > attr->ia_size) { | 1000 | if (i_size_read(inode) > attr->ia_size) { |
1002 | if (ocfs2_should_order_data(inode)) { | 1001 | if (ocfs2_should_order_data(inode)) { |
@@ -1836,6 +1835,8 @@ static int ocfs2_prepare_inode_for_write(struct dentry *dentry, | |||
1836 | &meta_level); | 1835 | &meta_level); |
1837 | if (has_refcount) | 1836 | if (has_refcount) |
1838 | *has_refcount = 1; | 1837 | *has_refcount = 1; |
1838 | if (direct_io) | ||
1839 | *direct_io = 0; | ||
1839 | } | 1840 | } |
1840 | 1841 | ||
1841 | if (ret < 0) { | 1842 | if (ret < 0) { |
@@ -1859,10 +1860,6 @@ static int ocfs2_prepare_inode_for_write(struct dentry *dentry, | |||
1859 | break; | 1860 | break; |
1860 | } | 1861 | } |
1861 | 1862 | ||
1862 | if (has_refcount && *has_refcount == 1) { | ||
1863 | *direct_io = 0; | ||
1864 | break; | ||
1865 | } | ||
1866 | /* | 1863 | /* |
1867 | * Allowing concurrent direct writes means | 1864 | * Allowing concurrent direct writes means |
1868 | * i_size changes wouldn't be synchronized, so | 1865 | * i_size changes wouldn't be synchronized, so |
@@ -2043,7 +2040,7 @@ out_dio: | |||
2043 | * async dio is going to do it in the future or an end_io after an | 2040 | * async dio is going to do it in the future or an end_io after an |
2044 | * error has already done it. | 2041 | * error has already done it. |
2045 | */ | 2042 | */ |
2046 | if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) { | 2043 | if ((ret == -EIOCBQUEUED) || (!ocfs2_iocb_is_rw_locked(iocb))) { |
2047 | rw_level = -1; | 2044 | rw_level = -1; |
2048 | have_alloc_sem = 0; | 2045 | have_alloc_sem = 0; |
2049 | } | 2046 | } |
diff --git a/fs/ocfs2/ioctl.h b/fs/ocfs2/ioctl.h index cf9a5ee30fef..0cd5323bd3f0 100644 --- a/fs/ocfs2/ioctl.h +++ b/fs/ocfs2/ioctl.h | |||
@@ -7,10 +7,10 @@ | |||
7 | * | 7 | * |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #ifndef OCFS2_IOCTL_H | 10 | #ifndef OCFS2_IOCTL_PROTO_H |
11 | #define OCFS2_IOCTL_H | 11 | #define OCFS2_IOCTL_PROTO_H |
12 | 12 | ||
13 | long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); | 13 | long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); |
14 | long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg); | 14 | long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg); |
15 | 15 | ||
16 | #endif /* OCFS2_IOCTL_H */ | 16 | #endif /* OCFS2_IOCTL_PROTO_H */ |
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index ac10f83edb95..ca992d91f511 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c | |||
@@ -476,7 +476,7 @@ out_mutex: | |||
476 | 476 | ||
477 | out: | 477 | out: |
478 | if (!status) | 478 | if (!status) |
479 | ocfs2_init_inode_steal_slot(osb); | 479 | ocfs2_init_steal_slots(osb); |
480 | mlog_exit(status); | 480 | mlog_exit(status); |
481 | return status; | 481 | return status; |
482 | } | 482 | } |
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h index 740f448041e2..1238b491db90 100644 --- a/fs/ocfs2/ocfs2.h +++ b/fs/ocfs2/ocfs2.h | |||
@@ -42,6 +42,7 @@ | |||
42 | 42 | ||
43 | #include "ocfs2_fs.h" | 43 | #include "ocfs2_fs.h" |
44 | #include "ocfs2_lockid.h" | 44 | #include "ocfs2_lockid.h" |
45 | #include "ocfs2_ioctl.h" | ||
45 | 46 | ||
46 | /* For struct ocfs2_blockcheck_stats */ | 47 | /* For struct ocfs2_blockcheck_stats */ |
47 | #include "blockcheck.h" | 48 | #include "blockcheck.h" |
@@ -159,7 +160,7 @@ struct ocfs2_lock_res { | |||
159 | int l_level; | 160 | int l_level; |
160 | unsigned int l_ro_holders; | 161 | unsigned int l_ro_holders; |
161 | unsigned int l_ex_holders; | 162 | unsigned int l_ex_holders; |
162 | union ocfs2_dlm_lksb l_lksb; | 163 | struct ocfs2_dlm_lksb l_lksb; |
163 | 164 | ||
164 | /* used from AST/BAST funcs. */ | 165 | /* used from AST/BAST funcs. */ |
165 | enum ocfs2_ast_action l_action; | 166 | enum ocfs2_ast_action l_action; |
@@ -305,7 +306,9 @@ struct ocfs2_super | |||
305 | u32 s_next_generation; | 306 | u32 s_next_generation; |
306 | unsigned long osb_flags; | 307 | unsigned long osb_flags; |
307 | s16 s_inode_steal_slot; | 308 | s16 s_inode_steal_slot; |
309 | s16 s_meta_steal_slot; | ||
308 | atomic_t s_num_inodes_stolen; | 310 | atomic_t s_num_inodes_stolen; |
311 | atomic_t s_num_meta_stolen; | ||
309 | 312 | ||
310 | unsigned long s_mount_opt; | 313 | unsigned long s_mount_opt; |
311 | unsigned int s_atime_quantum; | 314 | unsigned int s_atime_quantum; |
@@ -760,33 +763,6 @@ static inline unsigned int ocfs2_megabytes_to_clusters(struct super_block *sb, | |||
760 | return megs << (20 - OCFS2_SB(sb)->s_clustersize_bits); | 763 | return megs << (20 - OCFS2_SB(sb)->s_clustersize_bits); |
761 | } | 764 | } |
762 | 765 | ||
763 | static inline void ocfs2_init_inode_steal_slot(struct ocfs2_super *osb) | ||
764 | { | ||
765 | spin_lock(&osb->osb_lock); | ||
766 | osb->s_inode_steal_slot = OCFS2_INVALID_SLOT; | ||
767 | spin_unlock(&osb->osb_lock); | ||
768 | atomic_set(&osb->s_num_inodes_stolen, 0); | ||
769 | } | ||
770 | |||
771 | static inline void ocfs2_set_inode_steal_slot(struct ocfs2_super *osb, | ||
772 | s16 slot) | ||
773 | { | ||
774 | spin_lock(&osb->osb_lock); | ||
775 | osb->s_inode_steal_slot = slot; | ||
776 | spin_unlock(&osb->osb_lock); | ||
777 | } | ||
778 | |||
779 | static inline s16 ocfs2_get_inode_steal_slot(struct ocfs2_super *osb) | ||
780 | { | ||
781 | s16 slot; | ||
782 | |||
783 | spin_lock(&osb->osb_lock); | ||
784 | slot = osb->s_inode_steal_slot; | ||
785 | spin_unlock(&osb->osb_lock); | ||
786 | |||
787 | return slot; | ||
788 | } | ||
789 | |||
790 | #define ocfs2_set_bit ext2_set_bit | 766 | #define ocfs2_set_bit ext2_set_bit |
791 | #define ocfs2_clear_bit ext2_clear_bit | 767 | #define ocfs2_clear_bit ext2_clear_bit |
792 | #define ocfs2_test_bit ext2_test_bit | 768 | #define ocfs2_test_bit ext2_test_bit |
diff --git a/fs/ocfs2/ocfs2_fs.h b/fs/ocfs2/ocfs2_fs.h index 7638a38c32bc..bb37218a7978 100644 --- a/fs/ocfs2/ocfs2_fs.h +++ b/fs/ocfs2/ocfs2_fs.h | |||
@@ -254,63 +254,6 @@ | |||
254 | * refcount tree */ | 254 | * refcount tree */ |
255 | 255 | ||
256 | /* | 256 | /* |
257 | * ioctl commands | ||
258 | */ | ||
259 | #define OCFS2_IOC_GETFLAGS _IOR('f', 1, long) | ||
260 | #define OCFS2_IOC_SETFLAGS _IOW('f', 2, long) | ||
261 | #define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int) | ||
262 | #define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int) | ||
263 | |||
264 | /* | ||
265 | * Space reservation / allocation / free ioctls and argument structure | ||
266 | * are designed to be compatible with XFS. | ||
267 | * | ||
268 | * ALLOCSP* and FREESP* are not and will never be supported, but are | ||
269 | * included here for completeness. | ||
270 | */ | ||
271 | struct ocfs2_space_resv { | ||
272 | __s16 l_type; | ||
273 | __s16 l_whence; | ||
274 | __s64 l_start; | ||
275 | __s64 l_len; /* len == 0 means until end of file */ | ||
276 | __s32 l_sysid; | ||
277 | __u32 l_pid; | ||
278 | __s32 l_pad[4]; /* reserve area */ | ||
279 | }; | ||
280 | |||
281 | #define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv) | ||
282 | #define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv) | ||
283 | #define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv) | ||
284 | #define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv) | ||
285 | #define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv) | ||
286 | #define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv) | ||
287 | #define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv) | ||
288 | #define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv) | ||
289 | |||
290 | /* Used to pass group descriptor data when online resize is done */ | ||
291 | struct ocfs2_new_group_input { | ||
292 | __u64 group; /* Group descriptor's blkno. */ | ||
293 | __u32 clusters; /* Total number of clusters in this group */ | ||
294 | __u32 frees; /* Total free clusters in this group */ | ||
295 | __u16 chain; /* Chain for this group */ | ||
296 | __u16 reserved1; | ||
297 | __u32 reserved2; | ||
298 | }; | ||
299 | |||
300 | #define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int) | ||
301 | #define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input) | ||
302 | #define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input) | ||
303 | |||
304 | /* Used to pass 2 file names to reflink. */ | ||
305 | struct reflink_arguments { | ||
306 | __u64 old_path; | ||
307 | __u64 new_path; | ||
308 | __u64 preserve; | ||
309 | }; | ||
310 | #define OCFS2_IOC_REFLINK _IOW('o', 4, struct reflink_arguments) | ||
311 | |||
312 | |||
313 | /* | ||
314 | * Journal Flags (ocfs2_dinode.id1.journal1.i_flags) | 257 | * Journal Flags (ocfs2_dinode.id1.journal1.i_flags) |
315 | */ | 258 | */ |
316 | #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */ | 259 | #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */ |
diff --git a/fs/ocfs2/ocfs2_ioctl.h b/fs/ocfs2/ocfs2_ioctl.h new file mode 100644 index 000000000000..2d3420af1a83 --- /dev/null +++ b/fs/ocfs2/ocfs2_ioctl.h | |||
@@ -0,0 +1,79 @@ | |||
1 | /* -*- mode: c; c-basic-offset: 8; -*- | ||
2 | * vim: noexpandtab sw=8 ts=8 sts=0: | ||
3 | * | ||
4 | * ocfs2_ioctl.h | ||
5 | * | ||
6 | * Defines OCFS2 ioctls. | ||
7 | * | ||
8 | * Copyright (C) 2010 Oracle. All rights reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public | ||
12 | * License, version 2, as published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | */ | ||
19 | |||
20 | #ifndef OCFS2_IOCTL_H | ||
21 | #define OCFS2_IOCTL_H | ||
22 | |||
23 | /* | ||
24 | * ioctl commands | ||
25 | */ | ||
26 | #define OCFS2_IOC_GETFLAGS _IOR('f', 1, long) | ||
27 | #define OCFS2_IOC_SETFLAGS _IOW('f', 2, long) | ||
28 | #define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int) | ||
29 | #define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int) | ||
30 | |||
31 | /* | ||
32 | * Space reservation / allocation / free ioctls and argument structure | ||
33 | * are designed to be compatible with XFS. | ||
34 | * | ||
35 | * ALLOCSP* and FREESP* are not and will never be supported, but are | ||
36 | * included here for completeness. | ||
37 | */ | ||
38 | struct ocfs2_space_resv { | ||
39 | __s16 l_type; | ||
40 | __s16 l_whence; | ||
41 | __s64 l_start; | ||
42 | __s64 l_len; /* len == 0 means until end of file */ | ||
43 | __s32 l_sysid; | ||
44 | __u32 l_pid; | ||
45 | __s32 l_pad[4]; /* reserve area */ | ||
46 | }; | ||
47 | |||
48 | #define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv) | ||
49 | #define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv) | ||
50 | #define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv) | ||
51 | #define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv) | ||
52 | #define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv) | ||
53 | #define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv) | ||
54 | #define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv) | ||
55 | #define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv) | ||
56 | |||
57 | /* Used to pass group descriptor data when online resize is done */ | ||
58 | struct ocfs2_new_group_input { | ||
59 | __u64 group; /* Group descriptor's blkno. */ | ||
60 | __u32 clusters; /* Total number of clusters in this group */ | ||
61 | __u32 frees; /* Total free clusters in this group */ | ||
62 | __u16 chain; /* Chain for this group */ | ||
63 | __u16 reserved1; | ||
64 | __u32 reserved2; | ||
65 | }; | ||
66 | |||
67 | #define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int) | ||
68 | #define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input) | ||
69 | #define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input) | ||
70 | |||
71 | /* Used to pass 2 file names to reflink. */ | ||
72 | struct reflink_arguments { | ||
73 | __u64 old_path; | ||
74 | __u64 new_path; | ||
75 | __u64 preserve; | ||
76 | }; | ||
77 | #define OCFS2_IOC_REFLINK _IOW('o', 4, struct reflink_arguments) | ||
78 | |||
79 | #endif /* OCFS2_IOCTL_H */ | ||
diff --git a/fs/ocfs2/ocfs2_lockingver.h b/fs/ocfs2/ocfs2_lockingver.h index 82d5eeac0fff..2e45c8d2ea7e 100644 --- a/fs/ocfs2/ocfs2_lockingver.h +++ b/fs/ocfs2/ocfs2_lockingver.h | |||
@@ -23,6 +23,8 @@ | |||
23 | /* | 23 | /* |
24 | * The protocol version for ocfs2 cluster locking. See dlmglue.c for | 24 | * The protocol version for ocfs2 cluster locking. See dlmglue.c for |
25 | * more details. | 25 | * more details. |
26 | * | ||
27 | * 1.0 - Initial locking version from ocfs2 1.4. | ||
26 | */ | 28 | */ |
27 | #define OCFS2_LOCKING_PROTOCOL_MAJOR 1 | 29 | #define OCFS2_LOCKING_PROTOCOL_MAJOR 1 |
28 | #define OCFS2_LOCKING_PROTOCOL_MINOR 0 | 30 | #define OCFS2_LOCKING_PROTOCOL_MINOR 0 |
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 8ae65c9c020c..fb6aa7acf54b 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c | |||
@@ -626,7 +626,7 @@ static int ocfs2_create_refcount_tree(struct inode *inode, | |||
626 | rb = (struct ocfs2_refcount_block *)new_bh->b_data; | 626 | rb = (struct ocfs2_refcount_block *)new_bh->b_data; |
627 | memset(rb, 0, inode->i_sb->s_blocksize); | 627 | memset(rb, 0, inode->i_sb->s_blocksize); |
628 | strcpy((void *)rb, OCFS2_REFCOUNT_BLOCK_SIGNATURE); | 628 | strcpy((void *)rb, OCFS2_REFCOUNT_BLOCK_SIGNATURE); |
629 | rb->rf_suballoc_slot = cpu_to_le16(osb->slot_num); | 629 | rb->rf_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot); |
630 | rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start); | 630 | rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start); |
631 | rb->rf_fs_generation = cpu_to_le32(osb->fs_generation); | 631 | rb->rf_fs_generation = cpu_to_le32(osb->fs_generation); |
632 | rb->rf_blkno = cpu_to_le64(first_blkno); | 632 | rb->rf_blkno = cpu_to_le64(first_blkno); |
@@ -1330,7 +1330,7 @@ static int ocfs2_expand_inline_ref_root(handle_t *handle, | |||
1330 | memcpy(new_bh->b_data, ref_root_bh->b_data, sb->s_blocksize); | 1330 | memcpy(new_bh->b_data, ref_root_bh->b_data, sb->s_blocksize); |
1331 | 1331 | ||
1332 | new_rb = (struct ocfs2_refcount_block *)new_bh->b_data; | 1332 | new_rb = (struct ocfs2_refcount_block *)new_bh->b_data; |
1333 | new_rb->rf_suballoc_slot = cpu_to_le16(OCFS2_SB(sb)->slot_num); | 1333 | new_rb->rf_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot); |
1334 | new_rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start); | 1334 | new_rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start); |
1335 | new_rb->rf_blkno = cpu_to_le64(blkno); | 1335 | new_rb->rf_blkno = cpu_to_le64(blkno); |
1336 | new_rb->rf_cpos = cpu_to_le32(0); | 1336 | new_rb->rf_cpos = cpu_to_le32(0); |
@@ -1576,7 +1576,7 @@ static int ocfs2_new_leaf_refcount_block(handle_t *handle, | |||
1576 | new_rb = (struct ocfs2_refcount_block *)new_bh->b_data; | 1576 | new_rb = (struct ocfs2_refcount_block *)new_bh->b_data; |
1577 | memset(new_rb, 0, sb->s_blocksize); | 1577 | memset(new_rb, 0, sb->s_blocksize); |
1578 | strcpy((void *)new_rb, OCFS2_REFCOUNT_BLOCK_SIGNATURE); | 1578 | strcpy((void *)new_rb, OCFS2_REFCOUNT_BLOCK_SIGNATURE); |
1579 | new_rb->rf_suballoc_slot = cpu_to_le16(OCFS2_SB(sb)->slot_num); | 1579 | new_rb->rf_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot); |
1580 | new_rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start); | 1580 | new_rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start); |
1581 | new_rb->rf_fs_generation = cpu_to_le32(OCFS2_SB(sb)->fs_generation); | 1581 | new_rb->rf_fs_generation = cpu_to_le32(OCFS2_SB(sb)->fs_generation); |
1582 | new_rb->rf_blkno = cpu_to_le64(blkno); | 1582 | new_rb->rf_blkno = cpu_to_le64(blkno); |
diff --git a/fs/ocfs2/stack_o2cb.c b/fs/ocfs2/stack_o2cb.c index 3038c92af493..7020e1253ffa 100644 --- a/fs/ocfs2/stack_o2cb.c +++ b/fs/ocfs2/stack_o2cb.c | |||
@@ -161,24 +161,23 @@ static int dlm_status_to_errno(enum dlm_status status) | |||
161 | 161 | ||
162 | static void o2dlm_lock_ast_wrapper(void *astarg) | 162 | static void o2dlm_lock_ast_wrapper(void *astarg) |
163 | { | 163 | { |
164 | BUG_ON(o2cb_stack.sp_proto == NULL); | 164 | struct ocfs2_dlm_lksb *lksb = astarg; |
165 | 165 | ||
166 | o2cb_stack.sp_proto->lp_lock_ast(astarg); | 166 | lksb->lksb_conn->cc_proto->lp_lock_ast(lksb); |
167 | } | 167 | } |
168 | 168 | ||
169 | static void o2dlm_blocking_ast_wrapper(void *astarg, int level) | 169 | static void o2dlm_blocking_ast_wrapper(void *astarg, int level) |
170 | { | 170 | { |
171 | BUG_ON(o2cb_stack.sp_proto == NULL); | 171 | struct ocfs2_dlm_lksb *lksb = astarg; |
172 | 172 | ||
173 | o2cb_stack.sp_proto->lp_blocking_ast(astarg, level); | 173 | lksb->lksb_conn->cc_proto->lp_blocking_ast(lksb, level); |
174 | } | 174 | } |
175 | 175 | ||
176 | static void o2dlm_unlock_ast_wrapper(void *astarg, enum dlm_status status) | 176 | static void o2dlm_unlock_ast_wrapper(void *astarg, enum dlm_status status) |
177 | { | 177 | { |
178 | struct ocfs2_dlm_lksb *lksb = astarg; | ||
178 | int error = dlm_status_to_errno(status); | 179 | int error = dlm_status_to_errno(status); |
179 | 180 | ||
180 | BUG_ON(o2cb_stack.sp_proto == NULL); | ||
181 | |||
182 | /* | 181 | /* |
183 | * In o2dlm, you can get both the lock_ast() for the lock being | 182 | * In o2dlm, you can get both the lock_ast() for the lock being |
184 | * granted and the unlock_ast() for the CANCEL failing. A | 183 | * granted and the unlock_ast() for the CANCEL failing. A |
@@ -193,16 +192,15 @@ static void o2dlm_unlock_ast_wrapper(void *astarg, enum dlm_status status) | |||
193 | if (status == DLM_CANCELGRANT) | 192 | if (status == DLM_CANCELGRANT) |
194 | return; | 193 | return; |
195 | 194 | ||
196 | o2cb_stack.sp_proto->lp_unlock_ast(astarg, error); | 195 | lksb->lksb_conn->cc_proto->lp_unlock_ast(lksb, error); |
197 | } | 196 | } |
198 | 197 | ||
199 | static int o2cb_dlm_lock(struct ocfs2_cluster_connection *conn, | 198 | static int o2cb_dlm_lock(struct ocfs2_cluster_connection *conn, |
200 | int mode, | 199 | int mode, |
201 | union ocfs2_dlm_lksb *lksb, | 200 | struct ocfs2_dlm_lksb *lksb, |
202 | u32 flags, | 201 | u32 flags, |
203 | void *name, | 202 | void *name, |
204 | unsigned int namelen, | 203 | unsigned int namelen) |
205 | void *astarg) | ||
206 | { | 204 | { |
207 | enum dlm_status status; | 205 | enum dlm_status status; |
208 | int o2dlm_mode = mode_to_o2dlm(mode); | 206 | int o2dlm_mode = mode_to_o2dlm(mode); |
@@ -211,28 +209,27 @@ static int o2cb_dlm_lock(struct ocfs2_cluster_connection *conn, | |||
211 | 209 | ||
212 | status = dlmlock(conn->cc_lockspace, o2dlm_mode, &lksb->lksb_o2dlm, | 210 | status = dlmlock(conn->cc_lockspace, o2dlm_mode, &lksb->lksb_o2dlm, |
213 | o2dlm_flags, name, namelen, | 211 | o2dlm_flags, name, namelen, |
214 | o2dlm_lock_ast_wrapper, astarg, | 212 | o2dlm_lock_ast_wrapper, lksb, |
215 | o2dlm_blocking_ast_wrapper); | 213 | o2dlm_blocking_ast_wrapper); |
216 | ret = dlm_status_to_errno(status); | 214 | ret = dlm_status_to_errno(status); |
217 | return ret; | 215 | return ret; |
218 | } | 216 | } |
219 | 217 | ||
220 | static int o2cb_dlm_unlock(struct ocfs2_cluster_connection *conn, | 218 | static int o2cb_dlm_unlock(struct ocfs2_cluster_connection *conn, |
221 | union ocfs2_dlm_lksb *lksb, | 219 | struct ocfs2_dlm_lksb *lksb, |
222 | u32 flags, | 220 | u32 flags) |
223 | void *astarg) | ||
224 | { | 221 | { |
225 | enum dlm_status status; | 222 | enum dlm_status status; |
226 | int o2dlm_flags = flags_to_o2dlm(flags); | 223 | int o2dlm_flags = flags_to_o2dlm(flags); |
227 | int ret; | 224 | int ret; |
228 | 225 | ||
229 | status = dlmunlock(conn->cc_lockspace, &lksb->lksb_o2dlm, | 226 | status = dlmunlock(conn->cc_lockspace, &lksb->lksb_o2dlm, |
230 | o2dlm_flags, o2dlm_unlock_ast_wrapper, astarg); | 227 | o2dlm_flags, o2dlm_unlock_ast_wrapper, lksb); |
231 | ret = dlm_status_to_errno(status); | 228 | ret = dlm_status_to_errno(status); |
232 | return ret; | 229 | return ret; |
233 | } | 230 | } |
234 | 231 | ||
235 | static int o2cb_dlm_lock_status(union ocfs2_dlm_lksb *lksb) | 232 | static int o2cb_dlm_lock_status(struct ocfs2_dlm_lksb *lksb) |
236 | { | 233 | { |
237 | return dlm_status_to_errno(lksb->lksb_o2dlm.status); | 234 | return dlm_status_to_errno(lksb->lksb_o2dlm.status); |
238 | } | 235 | } |
@@ -242,17 +239,17 @@ static int o2cb_dlm_lock_status(union ocfs2_dlm_lksb *lksb) | |||
242 | * contents, it will zero out the LVB. Thus the caller can always trust | 239 | * contents, it will zero out the LVB. Thus the caller can always trust |
243 | * the contents. | 240 | * the contents. |
244 | */ | 241 | */ |
245 | static int o2cb_dlm_lvb_valid(union ocfs2_dlm_lksb *lksb) | 242 | static int o2cb_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb) |
246 | { | 243 | { |
247 | return 1; | 244 | return 1; |
248 | } | 245 | } |
249 | 246 | ||
250 | static void *o2cb_dlm_lvb(union ocfs2_dlm_lksb *lksb) | 247 | static void *o2cb_dlm_lvb(struct ocfs2_dlm_lksb *lksb) |
251 | { | 248 | { |
252 | return (void *)(lksb->lksb_o2dlm.lvb); | 249 | return (void *)(lksb->lksb_o2dlm.lvb); |
253 | } | 250 | } |
254 | 251 | ||
255 | static void o2cb_dump_lksb(union ocfs2_dlm_lksb *lksb) | 252 | static void o2cb_dump_lksb(struct ocfs2_dlm_lksb *lksb) |
256 | { | 253 | { |
257 | dlm_print_one_lock(lksb->lksb_o2dlm.lockid); | 254 | dlm_print_one_lock(lksb->lksb_o2dlm.lockid); |
258 | } | 255 | } |
@@ -280,7 +277,7 @@ static int o2cb_cluster_connect(struct ocfs2_cluster_connection *conn) | |||
280 | struct dlm_protocol_version fs_version; | 277 | struct dlm_protocol_version fs_version; |
281 | 278 | ||
282 | BUG_ON(conn == NULL); | 279 | BUG_ON(conn == NULL); |
283 | BUG_ON(o2cb_stack.sp_proto == NULL); | 280 | BUG_ON(conn->cc_proto == NULL); |
284 | 281 | ||
285 | /* for now we only have one cluster/node, make sure we see it | 282 | /* for now we only have one cluster/node, make sure we see it |
286 | * in the heartbeat universe */ | 283 | * in the heartbeat universe */ |
diff --git a/fs/ocfs2/stack_user.c b/fs/ocfs2/stack_user.c index da78a2a334fd..5ae8812b2864 100644 --- a/fs/ocfs2/stack_user.c +++ b/fs/ocfs2/stack_user.c | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <linux/reboot.h> | 25 | #include <linux/reboot.h> |
26 | #include <asm/uaccess.h> | 26 | #include <asm/uaccess.h> |
27 | 27 | ||
28 | #include "ocfs2.h" /* For struct ocfs2_lock_res */ | ||
29 | #include "stackglue.h" | 28 | #include "stackglue.h" |
30 | 29 | ||
31 | #include <linux/dlm_plock.h> | 30 | #include <linux/dlm_plock.h> |
@@ -63,8 +62,8 @@ | |||
63 | * negotiated by the client. The client negotiates based on the maximum | 62 | * negotiated by the client. The client negotiates based on the maximum |
64 | * version advertised in /sys/fs/ocfs2/max_locking_protocol. The major | 63 | * version advertised in /sys/fs/ocfs2/max_locking_protocol. The major |
65 | * number from the "SETV" message must match | 64 | * number from the "SETV" message must match |
66 | * ocfs2_user_plugin.sp_proto->lp_max_version.pv_major, and the minor number | 65 | * ocfs2_user_plugin.sp_max_proto.pv_major, and the minor number |
67 | * must be less than or equal to ...->lp_max_version.pv_minor. | 66 | * must be less than or equal to ...sp_max_version.pv_minor. |
68 | * | 67 | * |
69 | * Once this information has been set, mounts will be allowed. From this | 68 | * Once this information has been set, mounts will be allowed. From this |
70 | * point on, the "DOWN" message can be sent for node down notification. | 69 | * point on, the "DOWN" message can be sent for node down notification. |
@@ -401,7 +400,7 @@ static int ocfs2_control_do_setversion_msg(struct file *file, | |||
401 | char *ptr = NULL; | 400 | char *ptr = NULL; |
402 | struct ocfs2_control_private *p = file->private_data; | 401 | struct ocfs2_control_private *p = file->private_data; |
403 | struct ocfs2_protocol_version *max = | 402 | struct ocfs2_protocol_version *max = |
404 | &ocfs2_user_plugin.sp_proto->lp_max_version; | 403 | &ocfs2_user_plugin.sp_max_proto; |
405 | 404 | ||
406 | if (ocfs2_control_get_handshake_state(file) != | 405 | if (ocfs2_control_get_handshake_state(file) != |
407 | OCFS2_CONTROL_HANDSHAKE_PROTOCOL) | 406 | OCFS2_CONTROL_HANDSHAKE_PROTOCOL) |
@@ -664,18 +663,10 @@ static void ocfs2_control_exit(void) | |||
664 | -rc); | 663 | -rc); |
665 | } | 664 | } |
666 | 665 | ||
667 | static struct dlm_lksb *fsdlm_astarg_to_lksb(void *astarg) | ||
668 | { | ||
669 | struct ocfs2_lock_res *res = astarg; | ||
670 | return &res->l_lksb.lksb_fsdlm; | ||
671 | } | ||
672 | |||
673 | static void fsdlm_lock_ast_wrapper(void *astarg) | 666 | static void fsdlm_lock_ast_wrapper(void *astarg) |
674 | { | 667 | { |
675 | struct dlm_lksb *lksb = fsdlm_astarg_to_lksb(astarg); | 668 | struct ocfs2_dlm_lksb *lksb = astarg; |
676 | int status = lksb->sb_status; | 669 | int status = lksb->lksb_fsdlm.sb_status; |
677 | |||
678 | BUG_ON(ocfs2_user_plugin.sp_proto == NULL); | ||
679 | 670 | ||
680 | /* | 671 | /* |
681 | * For now we're punting on the issue of other non-standard errors | 672 | * For now we're punting on the issue of other non-standard errors |
@@ -688,25 +679,24 @@ static void fsdlm_lock_ast_wrapper(void *astarg) | |||
688 | */ | 679 | */ |
689 | 680 | ||
690 | if (status == -DLM_EUNLOCK || status == -DLM_ECANCEL) | 681 | if (status == -DLM_EUNLOCK || status == -DLM_ECANCEL) |
691 | ocfs2_user_plugin.sp_proto->lp_unlock_ast(astarg, 0); | 682 | lksb->lksb_conn->cc_proto->lp_unlock_ast(lksb, 0); |
692 | else | 683 | else |
693 | ocfs2_user_plugin.sp_proto->lp_lock_ast(astarg); | 684 | lksb->lksb_conn->cc_proto->lp_lock_ast(lksb); |
694 | } | 685 | } |
695 | 686 | ||
696 | static void fsdlm_blocking_ast_wrapper(void *astarg, int level) | 687 | static void fsdlm_blocking_ast_wrapper(void *astarg, int level) |
697 | { | 688 | { |
698 | BUG_ON(ocfs2_user_plugin.sp_proto == NULL); | 689 | struct ocfs2_dlm_lksb *lksb = astarg; |
699 | 690 | ||
700 | ocfs2_user_plugin.sp_proto->lp_blocking_ast(astarg, level); | 691 | lksb->lksb_conn->cc_proto->lp_blocking_ast(lksb, level); |
701 | } | 692 | } |
702 | 693 | ||
703 | static int user_dlm_lock(struct ocfs2_cluster_connection *conn, | 694 | static int user_dlm_lock(struct ocfs2_cluster_connection *conn, |
704 | int mode, | 695 | int mode, |
705 | union ocfs2_dlm_lksb *lksb, | 696 | struct ocfs2_dlm_lksb *lksb, |
706 | u32 flags, | 697 | u32 flags, |
707 | void *name, | 698 | void *name, |
708 | unsigned int namelen, | 699 | unsigned int namelen) |
709 | void *astarg) | ||
710 | { | 700 | { |
711 | int ret; | 701 | int ret; |
712 | 702 | ||
@@ -716,36 +706,35 @@ static int user_dlm_lock(struct ocfs2_cluster_connection *conn, | |||
716 | 706 | ||
717 | ret = dlm_lock(conn->cc_lockspace, mode, &lksb->lksb_fsdlm, | 707 | ret = dlm_lock(conn->cc_lockspace, mode, &lksb->lksb_fsdlm, |
718 | flags|DLM_LKF_NODLCKWT, name, namelen, 0, | 708 | flags|DLM_LKF_NODLCKWT, name, namelen, 0, |
719 | fsdlm_lock_ast_wrapper, astarg, | 709 | fsdlm_lock_ast_wrapper, lksb, |
720 | fsdlm_blocking_ast_wrapper); | 710 | fsdlm_blocking_ast_wrapper); |
721 | return ret; | 711 | return ret; |
722 | } | 712 | } |
723 | 713 | ||
724 | static int user_dlm_unlock(struct ocfs2_cluster_connection *conn, | 714 | static int user_dlm_unlock(struct ocfs2_cluster_connection *conn, |
725 | union ocfs2_dlm_lksb *lksb, | 715 | struct ocfs2_dlm_lksb *lksb, |
726 | u32 flags, | 716 | u32 flags) |
727 | void *astarg) | ||
728 | { | 717 | { |
729 | int ret; | 718 | int ret; |
730 | 719 | ||
731 | ret = dlm_unlock(conn->cc_lockspace, lksb->lksb_fsdlm.sb_lkid, | 720 | ret = dlm_unlock(conn->cc_lockspace, lksb->lksb_fsdlm.sb_lkid, |
732 | flags, &lksb->lksb_fsdlm, astarg); | 721 | flags, &lksb->lksb_fsdlm, lksb); |
733 | return ret; | 722 | return ret; |
734 | } | 723 | } |
735 | 724 | ||
736 | static int user_dlm_lock_status(union ocfs2_dlm_lksb *lksb) | 725 | static int user_dlm_lock_status(struct ocfs2_dlm_lksb *lksb) |
737 | { | 726 | { |
738 | return lksb->lksb_fsdlm.sb_status; | 727 | return lksb->lksb_fsdlm.sb_status; |
739 | } | 728 | } |
740 | 729 | ||
741 | static int user_dlm_lvb_valid(union ocfs2_dlm_lksb *lksb) | 730 | static int user_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb) |
742 | { | 731 | { |
743 | int invalid = lksb->lksb_fsdlm.sb_flags & DLM_SBF_VALNOTVALID; | 732 | int invalid = lksb->lksb_fsdlm.sb_flags & DLM_SBF_VALNOTVALID; |
744 | 733 | ||
745 | return !invalid; | 734 | return !invalid; |
746 | } | 735 | } |
747 | 736 | ||
748 | static void *user_dlm_lvb(union ocfs2_dlm_lksb *lksb) | 737 | static void *user_dlm_lvb(struct ocfs2_dlm_lksb *lksb) |
749 | { | 738 | { |
750 | if (!lksb->lksb_fsdlm.sb_lvbptr) | 739 | if (!lksb->lksb_fsdlm.sb_lvbptr) |
751 | lksb->lksb_fsdlm.sb_lvbptr = (char *)lksb + | 740 | lksb->lksb_fsdlm.sb_lvbptr = (char *)lksb + |
@@ -753,7 +742,7 @@ static void *user_dlm_lvb(union ocfs2_dlm_lksb *lksb) | |||
753 | return (void *)(lksb->lksb_fsdlm.sb_lvbptr); | 742 | return (void *)(lksb->lksb_fsdlm.sb_lvbptr); |
754 | } | 743 | } |
755 | 744 | ||
756 | static void user_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb) | 745 | static void user_dlm_dump_lksb(struct ocfs2_dlm_lksb *lksb) |
757 | { | 746 | { |
758 | } | 747 | } |
759 | 748 | ||
diff --git a/fs/ocfs2/stackglue.c b/fs/ocfs2/stackglue.c index f3df0baa9a48..39abf89697ed 100644 --- a/fs/ocfs2/stackglue.c +++ b/fs/ocfs2/stackglue.c | |||
@@ -36,7 +36,7 @@ | |||
36 | #define OCFS2_STACK_PLUGIN_USER "user" | 36 | #define OCFS2_STACK_PLUGIN_USER "user" |
37 | #define OCFS2_MAX_HB_CTL_PATH 256 | 37 | #define OCFS2_MAX_HB_CTL_PATH 256 |
38 | 38 | ||
39 | static struct ocfs2_locking_protocol *lproto; | 39 | static struct ocfs2_protocol_version locking_max_version; |
40 | static DEFINE_SPINLOCK(ocfs2_stack_lock); | 40 | static DEFINE_SPINLOCK(ocfs2_stack_lock); |
41 | static LIST_HEAD(ocfs2_stack_list); | 41 | static LIST_HEAD(ocfs2_stack_list); |
42 | static char cluster_stack_name[OCFS2_STACK_LABEL_LEN + 1]; | 42 | static char cluster_stack_name[OCFS2_STACK_LABEL_LEN + 1]; |
@@ -176,7 +176,7 @@ int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin) | |||
176 | spin_lock(&ocfs2_stack_lock); | 176 | spin_lock(&ocfs2_stack_lock); |
177 | if (!ocfs2_stack_lookup(plugin->sp_name)) { | 177 | if (!ocfs2_stack_lookup(plugin->sp_name)) { |
178 | plugin->sp_count = 0; | 178 | plugin->sp_count = 0; |
179 | plugin->sp_proto = lproto; | 179 | plugin->sp_max_proto = locking_max_version; |
180 | list_add(&plugin->sp_list, &ocfs2_stack_list); | 180 | list_add(&plugin->sp_list, &ocfs2_stack_list); |
181 | printk(KERN_INFO "ocfs2: Registered cluster interface %s\n", | 181 | printk(KERN_INFO "ocfs2: Registered cluster interface %s\n", |
182 | plugin->sp_name); | 182 | plugin->sp_name); |
@@ -213,77 +213,76 @@ void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin) | |||
213 | } | 213 | } |
214 | EXPORT_SYMBOL_GPL(ocfs2_stack_glue_unregister); | 214 | EXPORT_SYMBOL_GPL(ocfs2_stack_glue_unregister); |
215 | 215 | ||
216 | void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto) | 216 | void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_proto) |
217 | { | 217 | { |
218 | struct ocfs2_stack_plugin *p; | 218 | struct ocfs2_stack_plugin *p; |
219 | 219 | ||
220 | BUG_ON(proto == NULL); | ||
221 | |||
222 | spin_lock(&ocfs2_stack_lock); | 220 | spin_lock(&ocfs2_stack_lock); |
223 | BUG_ON(active_stack != NULL); | 221 | if (memcmp(max_proto, &locking_max_version, |
222 | sizeof(struct ocfs2_protocol_version))) { | ||
223 | BUG_ON(locking_max_version.pv_major != 0); | ||
224 | 224 | ||
225 | lproto = proto; | 225 | locking_max_version = *max_proto; |
226 | list_for_each_entry(p, &ocfs2_stack_list, sp_list) { | 226 | list_for_each_entry(p, &ocfs2_stack_list, sp_list) { |
227 | p->sp_proto = lproto; | 227 | p->sp_max_proto = locking_max_version; |
228 | } | ||
228 | } | 229 | } |
229 | |||
230 | spin_unlock(&ocfs2_stack_lock); | 230 | spin_unlock(&ocfs2_stack_lock); |
231 | } | 231 | } |
232 | EXPORT_SYMBOL_GPL(ocfs2_stack_glue_set_locking_protocol); | 232 | EXPORT_SYMBOL_GPL(ocfs2_stack_glue_set_max_proto_version); |
233 | 233 | ||
234 | 234 | ||
235 | /* | 235 | /* |
236 | * The ocfs2_dlm_lock() and ocfs2_dlm_unlock() functions take | 236 | * The ocfs2_dlm_lock() and ocfs2_dlm_unlock() functions take no argument |
237 | * "struct ocfs2_lock_res *astarg" instead of "void *astarg" because the | 237 | * for the ast and bast functions. They will pass the lksb to the ast |
238 | * underlying stack plugins need to pilfer the lksb off of the lock_res. | 238 | * and bast. The caller can wrap the lksb with their own structure to |
239 | * If some other structure needs to be passed as an astarg, the plugins | 239 | * get more information. |
240 | * will need to be given a different avenue to the lksb. | ||
241 | */ | 240 | */ |
242 | int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, | 241 | int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, |
243 | int mode, | 242 | int mode, |
244 | union ocfs2_dlm_lksb *lksb, | 243 | struct ocfs2_dlm_lksb *lksb, |
245 | u32 flags, | 244 | u32 flags, |
246 | void *name, | 245 | void *name, |
247 | unsigned int namelen, | 246 | unsigned int namelen) |
248 | struct ocfs2_lock_res *astarg) | ||
249 | { | 247 | { |
250 | BUG_ON(lproto == NULL); | 248 | if (!lksb->lksb_conn) |
251 | 249 | lksb->lksb_conn = conn; | |
250 | else | ||
251 | BUG_ON(lksb->lksb_conn != conn); | ||
252 | return active_stack->sp_ops->dlm_lock(conn, mode, lksb, flags, | 252 | return active_stack->sp_ops->dlm_lock(conn, mode, lksb, flags, |
253 | name, namelen, astarg); | 253 | name, namelen); |
254 | } | 254 | } |
255 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lock); | 255 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lock); |
256 | 256 | ||
257 | int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, | 257 | int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, |
258 | union ocfs2_dlm_lksb *lksb, | 258 | struct ocfs2_dlm_lksb *lksb, |
259 | u32 flags, | 259 | u32 flags) |
260 | struct ocfs2_lock_res *astarg) | ||
261 | { | 260 | { |
262 | BUG_ON(lproto == NULL); | 261 | BUG_ON(lksb->lksb_conn == NULL); |
263 | 262 | ||
264 | return active_stack->sp_ops->dlm_unlock(conn, lksb, flags, astarg); | 263 | return active_stack->sp_ops->dlm_unlock(conn, lksb, flags); |
265 | } | 264 | } |
266 | EXPORT_SYMBOL_GPL(ocfs2_dlm_unlock); | 265 | EXPORT_SYMBOL_GPL(ocfs2_dlm_unlock); |
267 | 266 | ||
268 | int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb) | 267 | int ocfs2_dlm_lock_status(struct ocfs2_dlm_lksb *lksb) |
269 | { | 268 | { |
270 | return active_stack->sp_ops->lock_status(lksb); | 269 | return active_stack->sp_ops->lock_status(lksb); |
271 | } | 270 | } |
272 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lock_status); | 271 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lock_status); |
273 | 272 | ||
274 | int ocfs2_dlm_lvb_valid(union ocfs2_dlm_lksb *lksb) | 273 | int ocfs2_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb) |
275 | { | 274 | { |
276 | return active_stack->sp_ops->lvb_valid(lksb); | 275 | return active_stack->sp_ops->lvb_valid(lksb); |
277 | } | 276 | } |
278 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb_valid); | 277 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb_valid); |
279 | 278 | ||
280 | void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb) | 279 | void *ocfs2_dlm_lvb(struct ocfs2_dlm_lksb *lksb) |
281 | { | 280 | { |
282 | return active_stack->sp_ops->lock_lvb(lksb); | 281 | return active_stack->sp_ops->lock_lvb(lksb); |
283 | } | 282 | } |
284 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb); | 283 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb); |
285 | 284 | ||
286 | void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb) | 285 | void ocfs2_dlm_dump_lksb(struct ocfs2_dlm_lksb *lksb) |
287 | { | 286 | { |
288 | active_stack->sp_ops->dump_lksb(lksb); | 287 | active_stack->sp_ops->dump_lksb(lksb); |
289 | } | 288 | } |
@@ -312,6 +311,7 @@ EXPORT_SYMBOL_GPL(ocfs2_plock); | |||
312 | int ocfs2_cluster_connect(const char *stack_name, | 311 | int ocfs2_cluster_connect(const char *stack_name, |
313 | const char *group, | 312 | const char *group, |
314 | int grouplen, | 313 | int grouplen, |
314 | struct ocfs2_locking_protocol *lproto, | ||
315 | void (*recovery_handler)(int node_num, | 315 | void (*recovery_handler)(int node_num, |
316 | void *recovery_data), | 316 | void *recovery_data), |
317 | void *recovery_data, | 317 | void *recovery_data, |
@@ -329,6 +329,12 @@ int ocfs2_cluster_connect(const char *stack_name, | |||
329 | goto out; | 329 | goto out; |
330 | } | 330 | } |
331 | 331 | ||
332 | if (memcmp(&lproto->lp_max_version, &locking_max_version, | ||
333 | sizeof(struct ocfs2_protocol_version))) { | ||
334 | rc = -EINVAL; | ||
335 | goto out; | ||
336 | } | ||
337 | |||
332 | new_conn = kzalloc(sizeof(struct ocfs2_cluster_connection), | 338 | new_conn = kzalloc(sizeof(struct ocfs2_cluster_connection), |
333 | GFP_KERNEL); | 339 | GFP_KERNEL); |
334 | if (!new_conn) { | 340 | if (!new_conn) { |
@@ -341,6 +347,7 @@ int ocfs2_cluster_connect(const char *stack_name, | |||
341 | new_conn->cc_recovery_handler = recovery_handler; | 347 | new_conn->cc_recovery_handler = recovery_handler; |
342 | new_conn->cc_recovery_data = recovery_data; | 348 | new_conn->cc_recovery_data = recovery_data; |
343 | 349 | ||
350 | new_conn->cc_proto = lproto; | ||
344 | /* Start the new connection at our maximum compatibility level */ | 351 | /* Start the new connection at our maximum compatibility level */ |
345 | new_conn->cc_version = lproto->lp_max_version; | 352 | new_conn->cc_version = lproto->lp_max_version; |
346 | 353 | ||
@@ -366,6 +373,24 @@ out: | |||
366 | } | 373 | } |
367 | EXPORT_SYMBOL_GPL(ocfs2_cluster_connect); | 374 | EXPORT_SYMBOL_GPL(ocfs2_cluster_connect); |
368 | 375 | ||
376 | /* The caller will ensure all nodes have the same cluster stack */ | ||
377 | int ocfs2_cluster_connect_agnostic(const char *group, | ||
378 | int grouplen, | ||
379 | struct ocfs2_locking_protocol *lproto, | ||
380 | void (*recovery_handler)(int node_num, | ||
381 | void *recovery_data), | ||
382 | void *recovery_data, | ||
383 | struct ocfs2_cluster_connection **conn) | ||
384 | { | ||
385 | char *stack_name = NULL; | ||
386 | |||
387 | if (cluster_stack_name[0]) | ||
388 | stack_name = cluster_stack_name; | ||
389 | return ocfs2_cluster_connect(stack_name, group, grouplen, lproto, | ||
390 | recovery_handler, recovery_data, conn); | ||
391 | } | ||
392 | EXPORT_SYMBOL_GPL(ocfs2_cluster_connect_agnostic); | ||
393 | |||
369 | /* If hangup_pending is 0, the stack driver will be dropped */ | 394 | /* If hangup_pending is 0, the stack driver will be dropped */ |
370 | int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn, | 395 | int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn, |
371 | int hangup_pending) | 396 | int hangup_pending) |
@@ -453,10 +478,10 @@ static ssize_t ocfs2_max_locking_protocol_show(struct kobject *kobj, | |||
453 | ssize_t ret = 0; | 478 | ssize_t ret = 0; |
454 | 479 | ||
455 | spin_lock(&ocfs2_stack_lock); | 480 | spin_lock(&ocfs2_stack_lock); |
456 | if (lproto) | 481 | if (locking_max_version.pv_major) |
457 | ret = snprintf(buf, PAGE_SIZE, "%u.%u\n", | 482 | ret = snprintf(buf, PAGE_SIZE, "%u.%u\n", |
458 | lproto->lp_max_version.pv_major, | 483 | locking_max_version.pv_major, |
459 | lproto->lp_max_version.pv_minor); | 484 | locking_max_version.pv_minor); |
460 | spin_unlock(&ocfs2_stack_lock); | 485 | spin_unlock(&ocfs2_stack_lock); |
461 | 486 | ||
462 | return ret; | 487 | return ret; |
@@ -685,7 +710,10 @@ static int __init ocfs2_stack_glue_init(void) | |||
685 | 710 | ||
686 | static void __exit ocfs2_stack_glue_exit(void) | 711 | static void __exit ocfs2_stack_glue_exit(void) |
687 | { | 712 | { |
688 | lproto = NULL; | 713 | memset(&locking_max_version, 0, |
714 | sizeof(struct ocfs2_protocol_version)); | ||
715 | locking_max_version.pv_major = 0; | ||
716 | locking_max_version.pv_minor = 0; | ||
689 | ocfs2_sysfs_exit(); | 717 | ocfs2_sysfs_exit(); |
690 | if (ocfs2_table_header) | 718 | if (ocfs2_table_header) |
691 | unregister_sysctl_table(ocfs2_table_header); | 719 | unregister_sysctl_table(ocfs2_table_header); |
diff --git a/fs/ocfs2/stackglue.h b/fs/ocfs2/stackglue.h index 03a44d60eac9..8ce7398ae1d2 100644 --- a/fs/ocfs2/stackglue.h +++ b/fs/ocfs2/stackglue.h | |||
@@ -56,17 +56,6 @@ struct ocfs2_protocol_version { | |||
56 | }; | 56 | }; |
57 | 57 | ||
58 | /* | 58 | /* |
59 | * The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf. | ||
60 | */ | ||
61 | struct ocfs2_locking_protocol { | ||
62 | struct ocfs2_protocol_version lp_max_version; | ||
63 | void (*lp_lock_ast)(void *astarg); | ||
64 | void (*lp_blocking_ast)(void *astarg, int level); | ||
65 | void (*lp_unlock_ast)(void *astarg, int error); | ||
66 | }; | ||
67 | |||
68 | |||
69 | /* | ||
70 | * The dlm_lockstatus struct includes lvb space, but the dlm_lksb struct only | 59 | * The dlm_lockstatus struct includes lvb space, but the dlm_lksb struct only |
71 | * has a pointer to separately allocated lvb space. This struct exists only to | 60 | * has a pointer to separately allocated lvb space. This struct exists only to |
72 | * include in the lksb union to make space for a combined dlm_lksb and lvb. | 61 | * include in the lksb union to make space for a combined dlm_lksb and lvb. |
@@ -81,12 +70,27 @@ struct fsdlm_lksb_plus_lvb { | |||
81 | * size of the union is known. Lock status structures are embedded in | 70 | * size of the union is known. Lock status structures are embedded in |
82 | * ocfs2 inodes. | 71 | * ocfs2 inodes. |
83 | */ | 72 | */ |
84 | union ocfs2_dlm_lksb { | 73 | struct ocfs2_cluster_connection; |
85 | struct dlm_lockstatus lksb_o2dlm; | 74 | struct ocfs2_dlm_lksb { |
86 | struct dlm_lksb lksb_fsdlm; | 75 | union { |
87 | struct fsdlm_lksb_plus_lvb padding; | 76 | struct dlm_lockstatus lksb_o2dlm; |
77 | struct dlm_lksb lksb_fsdlm; | ||
78 | struct fsdlm_lksb_plus_lvb padding; | ||
79 | }; | ||
80 | struct ocfs2_cluster_connection *lksb_conn; | ||
81 | }; | ||
82 | |||
83 | /* | ||
84 | * The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf. | ||
85 | */ | ||
86 | struct ocfs2_locking_protocol { | ||
87 | struct ocfs2_protocol_version lp_max_version; | ||
88 | void (*lp_lock_ast)(struct ocfs2_dlm_lksb *lksb); | ||
89 | void (*lp_blocking_ast)(struct ocfs2_dlm_lksb *lksb, int level); | ||
90 | void (*lp_unlock_ast)(struct ocfs2_dlm_lksb *lksb, int error); | ||
88 | }; | 91 | }; |
89 | 92 | ||
93 | |||
90 | /* | 94 | /* |
91 | * A cluster connection. Mostly opaque to ocfs2, the connection holds | 95 | * A cluster connection. Mostly opaque to ocfs2, the connection holds |
92 | * state for the underlying stack. ocfs2 does use cc_version to determine | 96 | * state for the underlying stack. ocfs2 does use cc_version to determine |
@@ -96,6 +100,7 @@ struct ocfs2_cluster_connection { | |||
96 | char cc_name[GROUP_NAME_MAX]; | 100 | char cc_name[GROUP_NAME_MAX]; |
97 | int cc_namelen; | 101 | int cc_namelen; |
98 | struct ocfs2_protocol_version cc_version; | 102 | struct ocfs2_protocol_version cc_version; |
103 | struct ocfs2_locking_protocol *cc_proto; | ||
99 | void (*cc_recovery_handler)(int node_num, void *recovery_data); | 104 | void (*cc_recovery_handler)(int node_num, void *recovery_data); |
100 | void *cc_recovery_data; | 105 | void *cc_recovery_data; |
101 | void *cc_lockspace; | 106 | void *cc_lockspace; |
@@ -155,27 +160,29 @@ struct ocfs2_stack_operations { | |||
155 | * | 160 | * |
156 | * ast and bast functions are not part of the call because the | 161 | * ast and bast functions are not part of the call because the |
157 | * stack will likely want to wrap ast and bast calls before passing | 162 | * stack will likely want to wrap ast and bast calls before passing |
158 | * them to stack->sp_proto. | 163 | * them to stack->sp_proto. There is no astarg. The lksb will |
164 | * be passed back to the ast and bast functions. The caller can | ||
165 | * use this to find their object. | ||
159 | */ | 166 | */ |
160 | int (*dlm_lock)(struct ocfs2_cluster_connection *conn, | 167 | int (*dlm_lock)(struct ocfs2_cluster_connection *conn, |
161 | int mode, | 168 | int mode, |
162 | union ocfs2_dlm_lksb *lksb, | 169 | struct ocfs2_dlm_lksb *lksb, |
163 | u32 flags, | 170 | u32 flags, |
164 | void *name, | 171 | void *name, |
165 | unsigned int namelen, | 172 | unsigned int namelen); |
166 | void *astarg); | ||
167 | 173 | ||
168 | /* | 174 | /* |
169 | * Call the underlying dlm unlock function. The ->dlm_unlock() | 175 | * Call the underlying dlm unlock function. The ->dlm_unlock() |
170 | * function should convert the flags as appropriate. | 176 | * function should convert the flags as appropriate. |
171 | * | 177 | * |
172 | * The unlock ast is not passed, as the stack will want to wrap | 178 | * The unlock ast is not passed, as the stack will want to wrap |
173 | * it before calling stack->sp_proto->lp_unlock_ast(). | 179 | * it before calling stack->sp_proto->lp_unlock_ast(). There is |
180 | * no astarg. The lksb will be passed back to the unlock ast | ||
181 | * function. The caller can use this to find their object. | ||
174 | */ | 182 | */ |
175 | int (*dlm_unlock)(struct ocfs2_cluster_connection *conn, | 183 | int (*dlm_unlock)(struct ocfs2_cluster_connection *conn, |
176 | union ocfs2_dlm_lksb *lksb, | 184 | struct ocfs2_dlm_lksb *lksb, |
177 | u32 flags, | 185 | u32 flags); |
178 | void *astarg); | ||
179 | 186 | ||
180 | /* | 187 | /* |
181 | * Return the status of the current lock status block. The fs | 188 | * Return the status of the current lock status block. The fs |
@@ -183,17 +190,17 @@ struct ocfs2_stack_operations { | |||
183 | * callback pulls out the stack-specific lksb, converts the status | 190 | * callback pulls out the stack-specific lksb, converts the status |
184 | * to a proper errno, and returns it. | 191 | * to a proper errno, and returns it. |
185 | */ | 192 | */ |
186 | int (*lock_status)(union ocfs2_dlm_lksb *lksb); | 193 | int (*lock_status)(struct ocfs2_dlm_lksb *lksb); |
187 | 194 | ||
188 | /* | 195 | /* |
189 | * Return non-zero if the LVB is valid. | 196 | * Return non-zero if the LVB is valid. |
190 | */ | 197 | */ |
191 | int (*lvb_valid)(union ocfs2_dlm_lksb *lksb); | 198 | int (*lvb_valid)(struct ocfs2_dlm_lksb *lksb); |
192 | 199 | ||
193 | /* | 200 | /* |
194 | * Pull the lvb pointer off of the stack-specific lksb. | 201 | * Pull the lvb pointer off of the stack-specific lksb. |
195 | */ | 202 | */ |
196 | void *(*lock_lvb)(union ocfs2_dlm_lksb *lksb); | 203 | void *(*lock_lvb)(struct ocfs2_dlm_lksb *lksb); |
197 | 204 | ||
198 | /* | 205 | /* |
199 | * Cluster-aware posix locks | 206 | * Cluster-aware posix locks |
@@ -210,7 +217,7 @@ struct ocfs2_stack_operations { | |||
210 | * This is an optoinal debugging hook. If provided, the | 217 | * This is an optoinal debugging hook. If provided, the |
211 | * stack can dump debugging information about this lock. | 218 | * stack can dump debugging information about this lock. |
212 | */ | 219 | */ |
213 | void (*dump_lksb)(union ocfs2_dlm_lksb *lksb); | 220 | void (*dump_lksb)(struct ocfs2_dlm_lksb *lksb); |
214 | }; | 221 | }; |
215 | 222 | ||
216 | /* | 223 | /* |
@@ -226,7 +233,7 @@ struct ocfs2_stack_plugin { | |||
226 | /* These are managed by the stackglue code. */ | 233 | /* These are managed by the stackglue code. */ |
227 | struct list_head sp_list; | 234 | struct list_head sp_list; |
228 | unsigned int sp_count; | 235 | unsigned int sp_count; |
229 | struct ocfs2_locking_protocol *sp_proto; | 236 | struct ocfs2_protocol_version sp_max_proto; |
230 | }; | 237 | }; |
231 | 238 | ||
232 | 239 | ||
@@ -234,10 +241,22 @@ struct ocfs2_stack_plugin { | |||
234 | int ocfs2_cluster_connect(const char *stack_name, | 241 | int ocfs2_cluster_connect(const char *stack_name, |
235 | const char *group, | 242 | const char *group, |
236 | int grouplen, | 243 | int grouplen, |
244 | struct ocfs2_locking_protocol *lproto, | ||
237 | void (*recovery_handler)(int node_num, | 245 | void (*recovery_handler)(int node_num, |
238 | void *recovery_data), | 246 | void *recovery_data), |
239 | void *recovery_data, | 247 | void *recovery_data, |
240 | struct ocfs2_cluster_connection **conn); | 248 | struct ocfs2_cluster_connection **conn); |
249 | /* | ||
250 | * Used by callers that don't store their stack name. They must ensure | ||
251 | * all nodes have the same stack. | ||
252 | */ | ||
253 | int ocfs2_cluster_connect_agnostic(const char *group, | ||
254 | int grouplen, | ||
255 | struct ocfs2_locking_protocol *lproto, | ||
256 | void (*recovery_handler)(int node_num, | ||
257 | void *recovery_data), | ||
258 | void *recovery_data, | ||
259 | struct ocfs2_cluster_connection **conn); | ||
241 | int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn, | 260 | int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn, |
242 | int hangup_pending); | 261 | int hangup_pending); |
243 | void ocfs2_cluster_hangup(const char *group, int grouplen); | 262 | void ocfs2_cluster_hangup(const char *group, int grouplen); |
@@ -246,26 +265,24 @@ int ocfs2_cluster_this_node(unsigned int *node); | |||
246 | struct ocfs2_lock_res; | 265 | struct ocfs2_lock_res; |
247 | int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, | 266 | int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, |
248 | int mode, | 267 | int mode, |
249 | union ocfs2_dlm_lksb *lksb, | 268 | struct ocfs2_dlm_lksb *lksb, |
250 | u32 flags, | 269 | u32 flags, |
251 | void *name, | 270 | void *name, |
252 | unsigned int namelen, | 271 | unsigned int namelen); |
253 | struct ocfs2_lock_res *astarg); | ||
254 | int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, | 272 | int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, |
255 | union ocfs2_dlm_lksb *lksb, | 273 | struct ocfs2_dlm_lksb *lksb, |
256 | u32 flags, | 274 | u32 flags); |
257 | struct ocfs2_lock_res *astarg); | ||
258 | 275 | ||
259 | int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb); | 276 | int ocfs2_dlm_lock_status(struct ocfs2_dlm_lksb *lksb); |
260 | int ocfs2_dlm_lvb_valid(union ocfs2_dlm_lksb *lksb); | 277 | int ocfs2_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb); |
261 | void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb); | 278 | void *ocfs2_dlm_lvb(struct ocfs2_dlm_lksb *lksb); |
262 | void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb); | 279 | void ocfs2_dlm_dump_lksb(struct ocfs2_dlm_lksb *lksb); |
263 | 280 | ||
264 | int ocfs2_stack_supports_plocks(void); | 281 | int ocfs2_stack_supports_plocks(void); |
265 | int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino, | 282 | int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino, |
266 | struct file *file, int cmd, struct file_lock *fl); | 283 | struct file *file, int cmd, struct file_lock *fl); |
267 | 284 | ||
268 | void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto); | 285 | void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_proto); |
269 | 286 | ||
270 | 287 | ||
271 | /* Used by stack plugins */ | 288 | /* Used by stack plugins */ |
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index c30b644d9572..c3c60bc3e072 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c | |||
@@ -51,7 +51,7 @@ | |||
51 | #define ALLOC_NEW_GROUP 0x1 | 51 | #define ALLOC_NEW_GROUP 0x1 |
52 | #define ALLOC_GROUPS_FROM_GLOBAL 0x2 | 52 | #define ALLOC_GROUPS_FROM_GLOBAL 0x2 |
53 | 53 | ||
54 | #define OCFS2_MAX_INODES_TO_STEAL 1024 | 54 | #define OCFS2_MAX_TO_STEAL 1024 |
55 | 55 | ||
56 | static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg); | 56 | static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg); |
57 | static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe); | 57 | static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe); |
@@ -637,12 +637,113 @@ bail: | |||
637 | return status; | 637 | return status; |
638 | } | 638 | } |
639 | 639 | ||
640 | static void ocfs2_init_inode_steal_slot(struct ocfs2_super *osb) | ||
641 | { | ||
642 | spin_lock(&osb->osb_lock); | ||
643 | osb->s_inode_steal_slot = OCFS2_INVALID_SLOT; | ||
644 | spin_unlock(&osb->osb_lock); | ||
645 | atomic_set(&osb->s_num_inodes_stolen, 0); | ||
646 | } | ||
647 | |||
648 | static void ocfs2_init_meta_steal_slot(struct ocfs2_super *osb) | ||
649 | { | ||
650 | spin_lock(&osb->osb_lock); | ||
651 | osb->s_meta_steal_slot = OCFS2_INVALID_SLOT; | ||
652 | spin_unlock(&osb->osb_lock); | ||
653 | atomic_set(&osb->s_num_meta_stolen, 0); | ||
654 | } | ||
655 | |||
656 | void ocfs2_init_steal_slots(struct ocfs2_super *osb) | ||
657 | { | ||
658 | ocfs2_init_inode_steal_slot(osb); | ||
659 | ocfs2_init_meta_steal_slot(osb); | ||
660 | } | ||
661 | |||
662 | static void __ocfs2_set_steal_slot(struct ocfs2_super *osb, int slot, int type) | ||
663 | { | ||
664 | spin_lock(&osb->osb_lock); | ||
665 | if (type == INODE_ALLOC_SYSTEM_INODE) | ||
666 | osb->s_inode_steal_slot = slot; | ||
667 | else if (type == EXTENT_ALLOC_SYSTEM_INODE) | ||
668 | osb->s_meta_steal_slot = slot; | ||
669 | spin_unlock(&osb->osb_lock); | ||
670 | } | ||
671 | |||
672 | static int __ocfs2_get_steal_slot(struct ocfs2_super *osb, int type) | ||
673 | { | ||
674 | int slot = OCFS2_INVALID_SLOT; | ||
675 | |||
676 | spin_lock(&osb->osb_lock); | ||
677 | if (type == INODE_ALLOC_SYSTEM_INODE) | ||
678 | slot = osb->s_inode_steal_slot; | ||
679 | else if (type == EXTENT_ALLOC_SYSTEM_INODE) | ||
680 | slot = osb->s_meta_steal_slot; | ||
681 | spin_unlock(&osb->osb_lock); | ||
682 | |||
683 | return slot; | ||
684 | } | ||
685 | |||
686 | static int ocfs2_get_inode_steal_slot(struct ocfs2_super *osb) | ||
687 | { | ||
688 | return __ocfs2_get_steal_slot(osb, INODE_ALLOC_SYSTEM_INODE); | ||
689 | } | ||
690 | |||
691 | static int ocfs2_get_meta_steal_slot(struct ocfs2_super *osb) | ||
692 | { | ||
693 | return __ocfs2_get_steal_slot(osb, EXTENT_ALLOC_SYSTEM_INODE); | ||
694 | } | ||
695 | |||
696 | static int ocfs2_steal_resource(struct ocfs2_super *osb, | ||
697 | struct ocfs2_alloc_context *ac, | ||
698 | int type) | ||
699 | { | ||
700 | int i, status = -ENOSPC; | ||
701 | int slot = __ocfs2_get_steal_slot(osb, type); | ||
702 | |||
703 | /* Start to steal resource from the first slot after ours. */ | ||
704 | if (slot == OCFS2_INVALID_SLOT) | ||
705 | slot = osb->slot_num + 1; | ||
706 | |||
707 | for (i = 0; i < osb->max_slots; i++, slot++) { | ||
708 | if (slot == osb->max_slots) | ||
709 | slot = 0; | ||
710 | |||
711 | if (slot == osb->slot_num) | ||
712 | continue; | ||
713 | |||
714 | status = ocfs2_reserve_suballoc_bits(osb, ac, | ||
715 | type, | ||
716 | (u32)slot, NULL, | ||
717 | NOT_ALLOC_NEW_GROUP); | ||
718 | if (status >= 0) { | ||
719 | __ocfs2_set_steal_slot(osb, slot, type); | ||
720 | break; | ||
721 | } | ||
722 | |||
723 | ocfs2_free_ac_resource(ac); | ||
724 | } | ||
725 | |||
726 | return status; | ||
727 | } | ||
728 | |||
729 | static int ocfs2_steal_inode(struct ocfs2_super *osb, | ||
730 | struct ocfs2_alloc_context *ac) | ||
731 | { | ||
732 | return ocfs2_steal_resource(osb, ac, INODE_ALLOC_SYSTEM_INODE); | ||
733 | } | ||
734 | |||
735 | static int ocfs2_steal_meta(struct ocfs2_super *osb, | ||
736 | struct ocfs2_alloc_context *ac) | ||
737 | { | ||
738 | return ocfs2_steal_resource(osb, ac, EXTENT_ALLOC_SYSTEM_INODE); | ||
739 | } | ||
740 | |||
640 | int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb, | 741 | int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb, |
641 | int blocks, | 742 | int blocks, |
642 | struct ocfs2_alloc_context **ac) | 743 | struct ocfs2_alloc_context **ac) |
643 | { | 744 | { |
644 | int status; | 745 | int status; |
645 | u32 slot; | 746 | int slot = ocfs2_get_meta_steal_slot(osb); |
646 | 747 | ||
647 | *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL); | 748 | *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL); |
648 | if (!(*ac)) { | 749 | if (!(*ac)) { |
@@ -653,12 +754,34 @@ int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb, | |||
653 | 754 | ||
654 | (*ac)->ac_bits_wanted = blocks; | 755 | (*ac)->ac_bits_wanted = blocks; |
655 | (*ac)->ac_which = OCFS2_AC_USE_META; | 756 | (*ac)->ac_which = OCFS2_AC_USE_META; |
656 | slot = osb->slot_num; | ||
657 | (*ac)->ac_group_search = ocfs2_block_group_search; | 757 | (*ac)->ac_group_search = ocfs2_block_group_search; |
658 | 758 | ||
759 | if (slot != OCFS2_INVALID_SLOT && | ||
760 | atomic_read(&osb->s_num_meta_stolen) < OCFS2_MAX_TO_STEAL) | ||
761 | goto extent_steal; | ||
762 | |||
763 | atomic_set(&osb->s_num_meta_stolen, 0); | ||
659 | status = ocfs2_reserve_suballoc_bits(osb, (*ac), | 764 | status = ocfs2_reserve_suballoc_bits(osb, (*ac), |
660 | EXTENT_ALLOC_SYSTEM_INODE, | 765 | EXTENT_ALLOC_SYSTEM_INODE, |
661 | slot, NULL, ALLOC_NEW_GROUP); | 766 | (u32)osb->slot_num, NULL, |
767 | ALLOC_NEW_GROUP); | ||
768 | |||
769 | |||
770 | if (status >= 0) { | ||
771 | status = 0; | ||
772 | if (slot != OCFS2_INVALID_SLOT) | ||
773 | ocfs2_init_meta_steal_slot(osb); | ||
774 | goto bail; | ||
775 | } else if (status < 0 && status != -ENOSPC) { | ||
776 | mlog_errno(status); | ||
777 | goto bail; | ||
778 | } | ||
779 | |||
780 | ocfs2_free_ac_resource(*ac); | ||
781 | |||
782 | extent_steal: | ||
783 | status = ocfs2_steal_meta(osb, *ac); | ||
784 | atomic_inc(&osb->s_num_meta_stolen); | ||
662 | if (status < 0) { | 785 | if (status < 0) { |
663 | if (status != -ENOSPC) | 786 | if (status != -ENOSPC) |
664 | mlog_errno(status); | 787 | mlog_errno(status); |
@@ -685,43 +808,11 @@ int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, | |||
685 | ac); | 808 | ac); |
686 | } | 809 | } |
687 | 810 | ||
688 | static int ocfs2_steal_inode_from_other_nodes(struct ocfs2_super *osb, | ||
689 | struct ocfs2_alloc_context *ac) | ||
690 | { | ||
691 | int i, status = -ENOSPC; | ||
692 | s16 slot = ocfs2_get_inode_steal_slot(osb); | ||
693 | |||
694 | /* Start to steal inodes from the first slot after ours. */ | ||
695 | if (slot == OCFS2_INVALID_SLOT) | ||
696 | slot = osb->slot_num + 1; | ||
697 | |||
698 | for (i = 0; i < osb->max_slots; i++, slot++) { | ||
699 | if (slot == osb->max_slots) | ||
700 | slot = 0; | ||
701 | |||
702 | if (slot == osb->slot_num) | ||
703 | continue; | ||
704 | |||
705 | status = ocfs2_reserve_suballoc_bits(osb, ac, | ||
706 | INODE_ALLOC_SYSTEM_INODE, | ||
707 | slot, NULL, | ||
708 | NOT_ALLOC_NEW_GROUP); | ||
709 | if (status >= 0) { | ||
710 | ocfs2_set_inode_steal_slot(osb, slot); | ||
711 | break; | ||
712 | } | ||
713 | |||
714 | ocfs2_free_ac_resource(ac); | ||
715 | } | ||
716 | |||
717 | return status; | ||
718 | } | ||
719 | |||
720 | int ocfs2_reserve_new_inode(struct ocfs2_super *osb, | 811 | int ocfs2_reserve_new_inode(struct ocfs2_super *osb, |
721 | struct ocfs2_alloc_context **ac) | 812 | struct ocfs2_alloc_context **ac) |
722 | { | 813 | { |
723 | int status; | 814 | int status; |
724 | s16 slot = ocfs2_get_inode_steal_slot(osb); | 815 | int slot = ocfs2_get_inode_steal_slot(osb); |
725 | u64 alloc_group; | 816 | u64 alloc_group; |
726 | 817 | ||
727 | *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL); | 818 | *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL); |
@@ -754,14 +845,14 @@ int ocfs2_reserve_new_inode(struct ocfs2_super *osb, | |||
754 | * need to check our slots to see whether there is some space for us. | 845 | * need to check our slots to see whether there is some space for us. |
755 | */ | 846 | */ |
756 | if (slot != OCFS2_INVALID_SLOT && | 847 | if (slot != OCFS2_INVALID_SLOT && |
757 | atomic_read(&osb->s_num_inodes_stolen) < OCFS2_MAX_INODES_TO_STEAL) | 848 | atomic_read(&osb->s_num_inodes_stolen) < OCFS2_MAX_TO_STEAL) |
758 | goto inode_steal; | 849 | goto inode_steal; |
759 | 850 | ||
760 | atomic_set(&osb->s_num_inodes_stolen, 0); | 851 | atomic_set(&osb->s_num_inodes_stolen, 0); |
761 | alloc_group = osb->osb_inode_alloc_group; | 852 | alloc_group = osb->osb_inode_alloc_group; |
762 | status = ocfs2_reserve_suballoc_bits(osb, *ac, | 853 | status = ocfs2_reserve_suballoc_bits(osb, *ac, |
763 | INODE_ALLOC_SYSTEM_INODE, | 854 | INODE_ALLOC_SYSTEM_INODE, |
764 | osb->slot_num, | 855 | (u32)osb->slot_num, |
765 | &alloc_group, | 856 | &alloc_group, |
766 | ALLOC_NEW_GROUP | | 857 | ALLOC_NEW_GROUP | |
767 | ALLOC_GROUPS_FROM_GLOBAL); | 858 | ALLOC_GROUPS_FROM_GLOBAL); |
@@ -789,7 +880,7 @@ int ocfs2_reserve_new_inode(struct ocfs2_super *osb, | |||
789 | ocfs2_free_ac_resource(*ac); | 880 | ocfs2_free_ac_resource(*ac); |
790 | 881 | ||
791 | inode_steal: | 882 | inode_steal: |
792 | status = ocfs2_steal_inode_from_other_nodes(osb, *ac); | 883 | status = ocfs2_steal_inode(osb, *ac); |
793 | atomic_inc(&osb->s_num_inodes_stolen); | 884 | atomic_inc(&osb->s_num_inodes_stolen); |
794 | if (status < 0) { | 885 | if (status < 0) { |
795 | if (status != -ENOSPC) | 886 | if (status != -ENOSPC) |
diff --git a/fs/ocfs2/suballoc.h b/fs/ocfs2/suballoc.h index 8c9a78a43164..fa60723c43e8 100644 --- a/fs/ocfs2/suballoc.h +++ b/fs/ocfs2/suballoc.h | |||
@@ -56,6 +56,7 @@ struct ocfs2_alloc_context { | |||
56 | is the same as ~0 - unlimited */ | 56 | is the same as ~0 - unlimited */ |
57 | }; | 57 | }; |
58 | 58 | ||
59 | void ocfs2_init_steal_slots(struct ocfs2_super *osb); | ||
59 | void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac); | 60 | void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac); |
60 | static inline int ocfs2_alloc_context_bits_left(struct ocfs2_alloc_context *ac) | 61 | static inline int ocfs2_alloc_context_bits_left(struct ocfs2_alloc_context *ac) |
61 | { | 62 | { |
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index 755cd49a5ef3..dee03197a494 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c | |||
@@ -69,6 +69,7 @@ | |||
69 | #include "xattr.h" | 69 | #include "xattr.h" |
70 | #include "quota.h" | 70 | #include "quota.h" |
71 | #include "refcounttree.h" | 71 | #include "refcounttree.h" |
72 | #include "suballoc.h" | ||
72 | 73 | ||
73 | #include "buffer_head_io.h" | 74 | #include "buffer_head_io.h" |
74 | 75 | ||
@@ -301,9 +302,12 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len) | |||
301 | 302 | ||
302 | spin_lock(&osb->osb_lock); | 303 | spin_lock(&osb->osb_lock); |
303 | out += snprintf(buf + out, len - out, | 304 | out += snprintf(buf + out, len - out, |
304 | "%10s => Slot: %d NumStolen: %d\n", "Steal", | 305 | "%10s => InodeSlot: %d StolenInodes: %d, " |
306 | "MetaSlot: %d StolenMeta: %d\n", "Steal", | ||
305 | osb->s_inode_steal_slot, | 307 | osb->s_inode_steal_slot, |
306 | atomic_read(&osb->s_num_inodes_stolen)); | 308 | atomic_read(&osb->s_num_inodes_stolen), |
309 | osb->s_meta_steal_slot, | ||
310 | atomic_read(&osb->s_num_meta_stolen)); | ||
307 | spin_unlock(&osb->osb_lock); | 311 | spin_unlock(&osb->osb_lock); |
308 | 312 | ||
309 | out += snprintf(buf + out, len - out, "OrphanScan => "); | 313 | out += snprintf(buf + out, len - out, "OrphanScan => "); |
@@ -1997,7 +2001,7 @@ static int ocfs2_initialize_super(struct super_block *sb, | |||
1997 | osb->blocked_lock_count = 0; | 2001 | osb->blocked_lock_count = 0; |
1998 | spin_lock_init(&osb->osb_lock); | 2002 | spin_lock_init(&osb->osb_lock); |
1999 | spin_lock_init(&osb->osb_xattr_lock); | 2003 | spin_lock_init(&osb->osb_xattr_lock); |
2000 | ocfs2_init_inode_steal_slot(osb); | 2004 | ocfs2_init_steal_slots(osb); |
2001 | 2005 | ||
2002 | atomic_set(&osb->alloc_stats.moves, 0); | 2006 | atomic_set(&osb->alloc_stats.moves, 0); |
2003 | atomic_set(&osb->alloc_stats.local_data, 0); | 2007 | atomic_set(&osb->alloc_stats.local_data, 0); |
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 8fc6fb071c6d..d1b0d386f6d1 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c | |||
@@ -116,10 +116,11 @@ static struct xattr_handler *ocfs2_xattr_handler_map[OCFS2_XATTR_MAX] = { | |||
116 | }; | 116 | }; |
117 | 117 | ||
118 | struct ocfs2_xattr_info { | 118 | struct ocfs2_xattr_info { |
119 | int name_index; | 119 | int xi_name_index; |
120 | const char *name; | 120 | const char *xi_name; |
121 | const void *value; | 121 | int xi_name_len; |
122 | size_t value_len; | 122 | const void *xi_value; |
123 | size_t xi_value_len; | ||
123 | }; | 124 | }; |
124 | 125 | ||
125 | struct ocfs2_xattr_search { | 126 | struct ocfs2_xattr_search { |
@@ -137,6 +138,115 @@ struct ocfs2_xattr_search { | |||
137 | int not_found; | 138 | int not_found; |
138 | }; | 139 | }; |
139 | 140 | ||
141 | /* Operations on struct ocfs2_xa_entry */ | ||
142 | struct ocfs2_xa_loc; | ||
143 | struct ocfs2_xa_loc_operations { | ||
144 | /* | ||
145 | * Journal functions | ||
146 | */ | ||
147 | int (*xlo_journal_access)(handle_t *handle, struct ocfs2_xa_loc *loc, | ||
148 | int type); | ||
149 | void (*xlo_journal_dirty)(handle_t *handle, struct ocfs2_xa_loc *loc); | ||
150 | |||
151 | /* | ||
152 | * Return a pointer to the appropriate buffer in loc->xl_storage | ||
153 | * at the given offset from loc->xl_header. | ||
154 | */ | ||
155 | void *(*xlo_offset_pointer)(struct ocfs2_xa_loc *loc, int offset); | ||
156 | |||
157 | /* Can we reuse the existing entry for the new value? */ | ||
158 | int (*xlo_can_reuse)(struct ocfs2_xa_loc *loc, | ||
159 | struct ocfs2_xattr_info *xi); | ||
160 | |||
161 | /* How much space is needed for the new value? */ | ||
162 | int (*xlo_check_space)(struct ocfs2_xa_loc *loc, | ||
163 | struct ocfs2_xattr_info *xi); | ||
164 | |||
165 | /* | ||
166 | * Return the offset of the first name+value pair. This is | ||
167 | * the start of our downward-filling free space. | ||
168 | */ | ||
169 | int (*xlo_get_free_start)(struct ocfs2_xa_loc *loc); | ||
170 | |||
171 | /* | ||
172 | * Remove the name+value at this location. Do whatever is | ||
173 | * appropriate with the remaining name+value pairs. | ||
174 | */ | ||
175 | void (*xlo_wipe_namevalue)(struct ocfs2_xa_loc *loc); | ||
176 | |||
177 | /* Fill xl_entry with a new entry */ | ||
178 | void (*xlo_add_entry)(struct ocfs2_xa_loc *loc, u32 name_hash); | ||
179 | |||
180 | /* Add name+value storage to an entry */ | ||
181 | void (*xlo_add_namevalue)(struct ocfs2_xa_loc *loc, int size); | ||
182 | |||
183 | /* | ||
184 | * Initialize the value buf's access and bh fields for this entry. | ||
185 | * ocfs2_xa_fill_value_buf() will handle the xv pointer. | ||
186 | */ | ||
187 | void (*xlo_fill_value_buf)(struct ocfs2_xa_loc *loc, | ||
188 | struct ocfs2_xattr_value_buf *vb); | ||
189 | }; | ||
190 | |||
191 | /* | ||
192 | * Describes an xattr entry location. This is a memory structure | ||
193 | * tracking the on-disk structure. | ||
194 | */ | ||
195 | struct ocfs2_xa_loc { | ||
196 | /* This xattr belongs to this inode */ | ||
197 | struct inode *xl_inode; | ||
198 | |||
199 | /* The ocfs2_xattr_header inside the on-disk storage. Not NULL. */ | ||
200 | struct ocfs2_xattr_header *xl_header; | ||
201 | |||
202 | /* Bytes from xl_header to the end of the storage */ | ||
203 | int xl_size; | ||
204 | |||
205 | /* | ||
206 | * The ocfs2_xattr_entry this location describes. If this is | ||
207 | * NULL, this location describes the on-disk structure where it | ||
208 | * would have been. | ||
209 | */ | ||
210 | struct ocfs2_xattr_entry *xl_entry; | ||
211 | |||
212 | /* | ||
213 | * Internal housekeeping | ||
214 | */ | ||
215 | |||
216 | /* Buffer(s) containing this entry */ | ||
217 | void *xl_storage; | ||
218 | |||
219 | /* Operations on the storage backing this location */ | ||
220 | const struct ocfs2_xa_loc_operations *xl_ops; | ||
221 | }; | ||
222 | |||
223 | /* | ||
224 | * Convenience functions to calculate how much space is needed for a | ||
225 | * given name+value pair | ||
226 | */ | ||
227 | static int namevalue_size(int name_len, uint64_t value_len) | ||
228 | { | ||
229 | if (value_len > OCFS2_XATTR_INLINE_SIZE) | ||
230 | return OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE; | ||
231 | else | ||
232 | return OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_SIZE(value_len); | ||
233 | } | ||
234 | |||
235 | static int namevalue_size_xi(struct ocfs2_xattr_info *xi) | ||
236 | { | ||
237 | return namevalue_size(xi->xi_name_len, xi->xi_value_len); | ||
238 | } | ||
239 | |||
240 | static int namevalue_size_xe(struct ocfs2_xattr_entry *xe) | ||
241 | { | ||
242 | u64 value_len = le64_to_cpu(xe->xe_value_size); | ||
243 | |||
244 | BUG_ON((value_len > OCFS2_XATTR_INLINE_SIZE) && | ||
245 | ocfs2_xattr_is_local(xe)); | ||
246 | return namevalue_size(xe->xe_name_len, value_len); | ||
247 | } | ||
248 | |||
249 | |||
140 | static int ocfs2_xattr_bucket_get_name_value(struct super_block *sb, | 250 | static int ocfs2_xattr_bucket_get_name_value(struct super_block *sb, |
141 | struct ocfs2_xattr_header *xh, | 251 | struct ocfs2_xattr_header *xh, |
142 | int index, | 252 | int index, |
@@ -212,14 +322,6 @@ static inline u16 ocfs2_blocks_per_xattr_bucket(struct super_block *sb) | |||
212 | return OCFS2_XATTR_BUCKET_SIZE / (1 << sb->s_blocksize_bits); | 322 | return OCFS2_XATTR_BUCKET_SIZE / (1 << sb->s_blocksize_bits); |
213 | } | 323 | } |
214 | 324 | ||
215 | static inline u16 ocfs2_xattr_max_xe_in_bucket(struct super_block *sb) | ||
216 | { | ||
217 | u16 len = sb->s_blocksize - | ||
218 | offsetof(struct ocfs2_xattr_header, xh_entries); | ||
219 | |||
220 | return len / sizeof(struct ocfs2_xattr_entry); | ||
221 | } | ||
222 | |||
223 | #define bucket_blkno(_b) ((_b)->bu_bhs[0]->b_blocknr) | 325 | #define bucket_blkno(_b) ((_b)->bu_bhs[0]->b_blocknr) |
224 | #define bucket_block(_b, _n) ((_b)->bu_bhs[(_n)]->b_data) | 326 | #define bucket_block(_b, _n) ((_b)->bu_bhs[(_n)]->b_data) |
225 | #define bucket_xh(_b) ((struct ocfs2_xattr_header *)bucket_block((_b), 0)) | 327 | #define bucket_xh(_b) ((struct ocfs2_xattr_header *)bucket_block((_b), 0)) |
@@ -463,35 +565,22 @@ static u32 ocfs2_xattr_name_hash(struct inode *inode, | |||
463 | return hash; | 565 | return hash; |
464 | } | 566 | } |
465 | 567 | ||
466 | /* | 568 | static int ocfs2_xattr_entry_real_size(int name_len, size_t value_len) |
467 | * ocfs2_xattr_hash_entry() | ||
468 | * | ||
469 | * Compute the hash of an extended attribute. | ||
470 | */ | ||
471 | static void ocfs2_xattr_hash_entry(struct inode *inode, | ||
472 | struct ocfs2_xattr_header *header, | ||
473 | struct ocfs2_xattr_entry *entry) | ||
474 | { | 569 | { |
475 | u32 hash = 0; | 570 | return namevalue_size(name_len, value_len) + |
476 | char *name = (char *)header + le16_to_cpu(entry->xe_name_offset); | 571 | sizeof(struct ocfs2_xattr_entry); |
477 | |||
478 | hash = ocfs2_xattr_name_hash(inode, name, entry->xe_name_len); | ||
479 | entry->xe_name_hash = cpu_to_le32(hash); | ||
480 | |||
481 | return; | ||
482 | } | 572 | } |
483 | 573 | ||
484 | static int ocfs2_xattr_entry_real_size(int name_len, size_t value_len) | 574 | static int ocfs2_xi_entry_usage(struct ocfs2_xattr_info *xi) |
485 | { | 575 | { |
486 | int size = 0; | 576 | return namevalue_size_xi(xi) + |
487 | 577 | sizeof(struct ocfs2_xattr_entry); | |
488 | if (value_len <= OCFS2_XATTR_INLINE_SIZE) | 578 | } |
489 | size = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_SIZE(value_len); | ||
490 | else | ||
491 | size = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE; | ||
492 | size += sizeof(struct ocfs2_xattr_entry); | ||
493 | 579 | ||
494 | return size; | 580 | static int ocfs2_xe_entry_usage(struct ocfs2_xattr_entry *xe) |
581 | { | ||
582 | return namevalue_size_xe(xe) + | ||
583 | sizeof(struct ocfs2_xattr_entry); | ||
495 | } | 584 | } |
496 | 585 | ||
497 | int ocfs2_calc_security_init(struct inode *dir, | 586 | int ocfs2_calc_security_init(struct inode *dir, |
@@ -1308,452 +1397,897 @@ out: | |||
1308 | return ret; | 1397 | return ret; |
1309 | } | 1398 | } |
1310 | 1399 | ||
1311 | static int ocfs2_xattr_cleanup(struct inode *inode, | 1400 | static int ocfs2_xa_check_space_helper(int needed_space, int free_start, |
1312 | handle_t *handle, | 1401 | int num_entries) |
1313 | struct ocfs2_xattr_info *xi, | ||
1314 | struct ocfs2_xattr_search *xs, | ||
1315 | struct ocfs2_xattr_value_buf *vb, | ||
1316 | size_t offs) | ||
1317 | { | 1402 | { |
1318 | int ret = 0; | 1403 | int free_space; |
1319 | size_t name_len = strlen(xi->name); | ||
1320 | void *val = xs->base + offs; | ||
1321 | size_t size = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE; | ||
1322 | 1404 | ||
1323 | ret = vb->vb_access(handle, INODE_CACHE(inode), vb->vb_bh, | 1405 | if (!needed_space) |
1324 | OCFS2_JOURNAL_ACCESS_WRITE); | 1406 | return 0; |
1325 | if (ret) { | ||
1326 | mlog_errno(ret); | ||
1327 | goto out; | ||
1328 | } | ||
1329 | /* Decrease xattr count */ | ||
1330 | le16_add_cpu(&xs->header->xh_count, -1); | ||
1331 | /* Remove the xattr entry and tree root which has already be set*/ | ||
1332 | memset((void *)xs->here, 0, sizeof(struct ocfs2_xattr_entry)); | ||
1333 | memset(val, 0, size); | ||
1334 | 1407 | ||
1335 | ret = ocfs2_journal_dirty(handle, vb->vb_bh); | 1408 | free_space = free_start - |
1336 | if (ret < 0) | 1409 | sizeof(struct ocfs2_xattr_header) - |
1337 | mlog_errno(ret); | 1410 | (num_entries * sizeof(struct ocfs2_xattr_entry)) - |
1338 | out: | 1411 | OCFS2_XATTR_HEADER_GAP; |
1339 | return ret; | 1412 | if (free_space < 0) |
1413 | return -EIO; | ||
1414 | if (free_space < needed_space) | ||
1415 | return -ENOSPC; | ||
1416 | |||
1417 | return 0; | ||
1340 | } | 1418 | } |
1341 | 1419 | ||
1342 | static int ocfs2_xattr_update_entry(struct inode *inode, | 1420 | static int ocfs2_xa_journal_access(handle_t *handle, struct ocfs2_xa_loc *loc, |
1343 | handle_t *handle, | 1421 | int type) |
1344 | struct ocfs2_xattr_info *xi, | ||
1345 | struct ocfs2_xattr_search *xs, | ||
1346 | struct ocfs2_xattr_value_buf *vb, | ||
1347 | size_t offs) | ||
1348 | { | 1422 | { |
1349 | int ret; | 1423 | return loc->xl_ops->xlo_journal_access(handle, loc, type); |
1424 | } | ||
1350 | 1425 | ||
1351 | ret = vb->vb_access(handle, INODE_CACHE(inode), vb->vb_bh, | 1426 | static void ocfs2_xa_journal_dirty(handle_t *handle, struct ocfs2_xa_loc *loc) |
1352 | OCFS2_JOURNAL_ACCESS_WRITE); | 1427 | { |
1353 | if (ret) { | 1428 | loc->xl_ops->xlo_journal_dirty(handle, loc); |
1354 | mlog_errno(ret); | 1429 | } |
1355 | goto out; | ||
1356 | } | ||
1357 | 1430 | ||
1358 | xs->here->xe_name_offset = cpu_to_le16(offs); | 1431 | /* Give a pointer into the storage for the given offset */ |
1359 | xs->here->xe_value_size = cpu_to_le64(xi->value_len); | 1432 | static void *ocfs2_xa_offset_pointer(struct ocfs2_xa_loc *loc, int offset) |
1360 | if (xi->value_len <= OCFS2_XATTR_INLINE_SIZE) | 1433 | { |
1361 | ocfs2_xattr_set_local(xs->here, 1); | 1434 | BUG_ON(offset >= loc->xl_size); |
1362 | else | 1435 | return loc->xl_ops->xlo_offset_pointer(loc, offset); |
1363 | ocfs2_xattr_set_local(xs->here, 0); | 1436 | } |
1364 | ocfs2_xattr_hash_entry(inode, xs->header, xs->here); | ||
1365 | 1437 | ||
1366 | ret = ocfs2_journal_dirty(handle, vb->vb_bh); | 1438 | /* |
1367 | if (ret < 0) | 1439 | * Wipe the name+value pair and allow the storage to reclaim it. This |
1368 | mlog_errno(ret); | 1440 | * must be followed by either removal of the entry or a call to |
1369 | out: | 1441 | * ocfs2_xa_add_namevalue(). |
1370 | return ret; | 1442 | */ |
1443 | static void ocfs2_xa_wipe_namevalue(struct ocfs2_xa_loc *loc) | ||
1444 | { | ||
1445 | loc->xl_ops->xlo_wipe_namevalue(loc); | ||
1371 | } | 1446 | } |
1372 | 1447 | ||
1373 | /* | 1448 | /* |
1374 | * ocfs2_xattr_set_value_outside() | 1449 | * Find lowest offset to a name+value pair. This is the start of our |
1375 | * | 1450 | * downward-growing free space. |
1376 | * Set large size value in B tree. | ||
1377 | */ | 1451 | */ |
1378 | static int ocfs2_xattr_set_value_outside(struct inode *inode, | 1452 | static int ocfs2_xa_get_free_start(struct ocfs2_xa_loc *loc) |
1379 | struct ocfs2_xattr_info *xi, | ||
1380 | struct ocfs2_xattr_search *xs, | ||
1381 | struct ocfs2_xattr_set_ctxt *ctxt, | ||
1382 | struct ocfs2_xattr_value_buf *vb, | ||
1383 | size_t offs) | ||
1384 | { | 1453 | { |
1385 | size_t name_len = strlen(xi->name); | 1454 | return loc->xl_ops->xlo_get_free_start(loc); |
1386 | void *val = xs->base + offs; | 1455 | } |
1387 | struct ocfs2_xattr_value_root *xv = NULL; | ||
1388 | size_t size = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE; | ||
1389 | int ret = 0; | ||
1390 | 1456 | ||
1391 | memset(val, 0, size); | 1457 | /* Can we reuse loc->xl_entry for xi? */ |
1392 | memcpy(val, xi->name, name_len); | 1458 | static int ocfs2_xa_can_reuse_entry(struct ocfs2_xa_loc *loc, |
1393 | xv = (struct ocfs2_xattr_value_root *) | 1459 | struct ocfs2_xattr_info *xi) |
1394 | (val + OCFS2_XATTR_SIZE(name_len)); | 1460 | { |
1395 | xv->xr_clusters = 0; | 1461 | return loc->xl_ops->xlo_can_reuse(loc, xi); |
1396 | xv->xr_last_eb_blk = 0; | 1462 | } |
1397 | xv->xr_list.l_tree_depth = 0; | 1463 | |
1398 | xv->xr_list.l_count = cpu_to_le16(1); | 1464 | /* How much free space is needed to set the new value */ |
1399 | xv->xr_list.l_next_free_rec = 0; | 1465 | static int ocfs2_xa_check_space(struct ocfs2_xa_loc *loc, |
1400 | vb->vb_xv = xv; | 1466 | struct ocfs2_xattr_info *xi) |
1401 | 1467 | { | |
1402 | ret = ocfs2_xattr_value_truncate(inode, vb, xi->value_len, ctxt); | 1468 | return loc->xl_ops->xlo_check_space(loc, xi); |
1403 | if (ret < 0) { | 1469 | } |
1404 | mlog_errno(ret); | 1470 | |
1405 | return ret; | 1471 | static void ocfs2_xa_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash) |
1472 | { | ||
1473 | loc->xl_ops->xlo_add_entry(loc, name_hash); | ||
1474 | loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash); | ||
1475 | /* | ||
1476 | * We can't leave the new entry's xe_name_offset at zero or | ||
1477 | * add_namevalue() will go nuts. We set it to the size of our | ||
1478 | * storage so that it can never be less than any other entry. | ||
1479 | */ | ||
1480 | loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size); | ||
1481 | } | ||
1482 | |||
1483 | static void ocfs2_xa_add_namevalue(struct ocfs2_xa_loc *loc, | ||
1484 | struct ocfs2_xattr_info *xi) | ||
1485 | { | ||
1486 | int size = namevalue_size_xi(xi); | ||
1487 | int nameval_offset; | ||
1488 | char *nameval_buf; | ||
1489 | |||
1490 | loc->xl_ops->xlo_add_namevalue(loc, size); | ||
1491 | loc->xl_entry->xe_value_size = cpu_to_le64(xi->xi_value_len); | ||
1492 | loc->xl_entry->xe_name_len = xi->xi_name_len; | ||
1493 | ocfs2_xattr_set_type(loc->xl_entry, xi->xi_name_index); | ||
1494 | ocfs2_xattr_set_local(loc->xl_entry, | ||
1495 | xi->xi_value_len <= OCFS2_XATTR_INLINE_SIZE); | ||
1496 | |||
1497 | nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset); | ||
1498 | nameval_buf = ocfs2_xa_offset_pointer(loc, nameval_offset); | ||
1499 | memset(nameval_buf, 0, size); | ||
1500 | memcpy(nameval_buf, xi->xi_name, xi->xi_name_len); | ||
1501 | } | ||
1502 | |||
1503 | static void ocfs2_xa_fill_value_buf(struct ocfs2_xa_loc *loc, | ||
1504 | struct ocfs2_xattr_value_buf *vb) | ||
1505 | { | ||
1506 | int nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset); | ||
1507 | int name_size = OCFS2_XATTR_SIZE(loc->xl_entry->xe_name_len); | ||
1508 | |||
1509 | /* Value bufs are for value trees */ | ||
1510 | BUG_ON(ocfs2_xattr_is_local(loc->xl_entry)); | ||
1511 | BUG_ON(namevalue_size_xe(loc->xl_entry) != | ||
1512 | (name_size + OCFS2_XATTR_ROOT_SIZE)); | ||
1513 | |||
1514 | loc->xl_ops->xlo_fill_value_buf(loc, vb); | ||
1515 | vb->vb_xv = | ||
1516 | (struct ocfs2_xattr_value_root *)ocfs2_xa_offset_pointer(loc, | ||
1517 | nameval_offset + | ||
1518 | name_size); | ||
1519 | } | ||
1520 | |||
1521 | static int ocfs2_xa_block_journal_access(handle_t *handle, | ||
1522 | struct ocfs2_xa_loc *loc, int type) | ||
1523 | { | ||
1524 | struct buffer_head *bh = loc->xl_storage; | ||
1525 | ocfs2_journal_access_func access; | ||
1526 | |||
1527 | if (loc->xl_size == (bh->b_size - | ||
1528 | offsetof(struct ocfs2_xattr_block, | ||
1529 | xb_attrs.xb_header))) | ||
1530 | access = ocfs2_journal_access_xb; | ||
1531 | else | ||
1532 | access = ocfs2_journal_access_di; | ||
1533 | return access(handle, INODE_CACHE(loc->xl_inode), bh, type); | ||
1534 | } | ||
1535 | |||
1536 | static void ocfs2_xa_block_journal_dirty(handle_t *handle, | ||
1537 | struct ocfs2_xa_loc *loc) | ||
1538 | { | ||
1539 | struct buffer_head *bh = loc->xl_storage; | ||
1540 | |||
1541 | ocfs2_journal_dirty(handle, bh); | ||
1542 | } | ||
1543 | |||
1544 | static void *ocfs2_xa_block_offset_pointer(struct ocfs2_xa_loc *loc, | ||
1545 | int offset) | ||
1546 | { | ||
1547 | return (char *)loc->xl_header + offset; | ||
1548 | } | ||
1549 | |||
1550 | static int ocfs2_xa_block_can_reuse(struct ocfs2_xa_loc *loc, | ||
1551 | struct ocfs2_xattr_info *xi) | ||
1552 | { | ||
1553 | /* | ||
1554 | * Block storage is strict. If the sizes aren't exact, we will | ||
1555 | * remove the old one and reinsert the new. | ||
1556 | */ | ||
1557 | return namevalue_size_xe(loc->xl_entry) == | ||
1558 | namevalue_size_xi(xi); | ||
1559 | } | ||
1560 | |||
1561 | static int ocfs2_xa_block_get_free_start(struct ocfs2_xa_loc *loc) | ||
1562 | { | ||
1563 | struct ocfs2_xattr_header *xh = loc->xl_header; | ||
1564 | int i, count = le16_to_cpu(xh->xh_count); | ||
1565 | int offset, free_start = loc->xl_size; | ||
1566 | |||
1567 | for (i = 0; i < count; i++) { | ||
1568 | offset = le16_to_cpu(xh->xh_entries[i].xe_name_offset); | ||
1569 | if (offset < free_start) | ||
1570 | free_start = offset; | ||
1406 | } | 1571 | } |
1407 | ret = ocfs2_xattr_update_entry(inode, ctxt->handle, xi, xs, vb, offs); | 1572 | |
1408 | if (ret < 0) { | 1573 | return free_start; |
1409 | mlog_errno(ret); | 1574 | } |
1410 | return ret; | 1575 | |
1576 | static int ocfs2_xa_block_check_space(struct ocfs2_xa_loc *loc, | ||
1577 | struct ocfs2_xattr_info *xi) | ||
1578 | { | ||
1579 | int count = le16_to_cpu(loc->xl_header->xh_count); | ||
1580 | int free_start = ocfs2_xa_get_free_start(loc); | ||
1581 | int needed_space = ocfs2_xi_entry_usage(xi); | ||
1582 | |||
1583 | /* | ||
1584 | * Block storage will reclaim the original entry before inserting | ||
1585 | * the new value, so we only need the difference. If the new | ||
1586 | * entry is smaller than the old one, we don't need anything. | ||
1587 | */ | ||
1588 | if (loc->xl_entry) { | ||
1589 | /* Don't need space if we're reusing! */ | ||
1590 | if (ocfs2_xa_can_reuse_entry(loc, xi)) | ||
1591 | needed_space = 0; | ||
1592 | else | ||
1593 | needed_space -= ocfs2_xe_entry_usage(loc->xl_entry); | ||
1411 | } | 1594 | } |
1412 | ret = __ocfs2_xattr_set_value_outside(inode, ctxt->handle, vb, | 1595 | if (needed_space < 0) |
1413 | xi->value, xi->value_len); | 1596 | needed_space = 0; |
1414 | if (ret < 0) | 1597 | return ocfs2_xa_check_space_helper(needed_space, free_start, count); |
1415 | mlog_errno(ret); | 1598 | } |
1416 | 1599 | ||
1417 | return ret; | 1600 | /* |
1601 | * Block storage for xattrs keeps the name+value pairs compacted. When | ||
1602 | * we remove one, we have to shift any that preceded it towards the end. | ||
1603 | */ | ||
1604 | static void ocfs2_xa_block_wipe_namevalue(struct ocfs2_xa_loc *loc) | ||
1605 | { | ||
1606 | int i, offset; | ||
1607 | int namevalue_offset, first_namevalue_offset, namevalue_size; | ||
1608 | struct ocfs2_xattr_entry *entry = loc->xl_entry; | ||
1609 | struct ocfs2_xattr_header *xh = loc->xl_header; | ||
1610 | int count = le16_to_cpu(xh->xh_count); | ||
1611 | |||
1612 | namevalue_offset = le16_to_cpu(entry->xe_name_offset); | ||
1613 | namevalue_size = namevalue_size_xe(entry); | ||
1614 | first_namevalue_offset = ocfs2_xa_get_free_start(loc); | ||
1615 | |||
1616 | /* Shift the name+value pairs */ | ||
1617 | memmove((char *)xh + first_namevalue_offset + namevalue_size, | ||
1618 | (char *)xh + first_namevalue_offset, | ||
1619 | namevalue_offset - first_namevalue_offset); | ||
1620 | memset((char *)xh + first_namevalue_offset, 0, namevalue_size); | ||
1621 | |||
1622 | /* Now tell xh->xh_entries about it */ | ||
1623 | for (i = 0; i < count; i++) { | ||
1624 | offset = le16_to_cpu(xh->xh_entries[i].xe_name_offset); | ||
1625 | if (offset < namevalue_offset) | ||
1626 | le16_add_cpu(&xh->xh_entries[i].xe_name_offset, | ||
1627 | namevalue_size); | ||
1628 | } | ||
1629 | |||
1630 | /* | ||
1631 | * Note that we don't update xh_free_start or xh_name_value_len | ||
1632 | * because they're not used in block-stored xattrs. | ||
1633 | */ | ||
1634 | } | ||
1635 | |||
1636 | static void ocfs2_xa_block_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash) | ||
1637 | { | ||
1638 | int count = le16_to_cpu(loc->xl_header->xh_count); | ||
1639 | loc->xl_entry = &(loc->xl_header->xh_entries[count]); | ||
1640 | le16_add_cpu(&loc->xl_header->xh_count, 1); | ||
1641 | memset(loc->xl_entry, 0, sizeof(struct ocfs2_xattr_entry)); | ||
1642 | } | ||
1643 | |||
1644 | static void ocfs2_xa_block_add_namevalue(struct ocfs2_xa_loc *loc, int size) | ||
1645 | { | ||
1646 | int free_start = ocfs2_xa_get_free_start(loc); | ||
1647 | |||
1648 | loc->xl_entry->xe_name_offset = cpu_to_le16(free_start - size); | ||
1649 | } | ||
1650 | |||
1651 | static void ocfs2_xa_block_fill_value_buf(struct ocfs2_xa_loc *loc, | ||
1652 | struct ocfs2_xattr_value_buf *vb) | ||
1653 | { | ||
1654 | struct buffer_head *bh = loc->xl_storage; | ||
1655 | |||
1656 | if (loc->xl_size == (bh->b_size - | ||
1657 | offsetof(struct ocfs2_xattr_block, | ||
1658 | xb_attrs.xb_header))) | ||
1659 | vb->vb_access = ocfs2_journal_access_xb; | ||
1660 | else | ||
1661 | vb->vb_access = ocfs2_journal_access_di; | ||
1662 | vb->vb_bh = bh; | ||
1418 | } | 1663 | } |
1419 | 1664 | ||
1420 | /* | 1665 | /* |
1421 | * ocfs2_xattr_set_entry_local() | 1666 | * Operations for xattrs stored in blocks. This includes inline inode |
1422 | * | 1667 | * storage and unindexed ocfs2_xattr_blocks. |
1423 | * Set, replace or remove extended attribute in local. | ||
1424 | */ | 1668 | */ |
1425 | static void ocfs2_xattr_set_entry_local(struct inode *inode, | 1669 | static const struct ocfs2_xa_loc_operations ocfs2_xa_block_loc_ops = { |
1426 | struct ocfs2_xattr_info *xi, | 1670 | .xlo_journal_access = ocfs2_xa_block_journal_access, |
1427 | struct ocfs2_xattr_search *xs, | 1671 | .xlo_journal_dirty = ocfs2_xa_block_journal_dirty, |
1428 | struct ocfs2_xattr_entry *last, | 1672 | .xlo_offset_pointer = ocfs2_xa_block_offset_pointer, |
1429 | size_t min_offs) | 1673 | .xlo_check_space = ocfs2_xa_block_check_space, |
1674 | .xlo_can_reuse = ocfs2_xa_block_can_reuse, | ||
1675 | .xlo_get_free_start = ocfs2_xa_block_get_free_start, | ||
1676 | .xlo_wipe_namevalue = ocfs2_xa_block_wipe_namevalue, | ||
1677 | .xlo_add_entry = ocfs2_xa_block_add_entry, | ||
1678 | .xlo_add_namevalue = ocfs2_xa_block_add_namevalue, | ||
1679 | .xlo_fill_value_buf = ocfs2_xa_block_fill_value_buf, | ||
1680 | }; | ||
1681 | |||
1682 | static int ocfs2_xa_bucket_journal_access(handle_t *handle, | ||
1683 | struct ocfs2_xa_loc *loc, int type) | ||
1430 | { | 1684 | { |
1431 | size_t name_len = strlen(xi->name); | 1685 | struct ocfs2_xattr_bucket *bucket = loc->xl_storage; |
1432 | int i; | ||
1433 | 1686 | ||
1434 | if (xi->value && xs->not_found) { | 1687 | return ocfs2_xattr_bucket_journal_access(handle, bucket, type); |
1435 | /* Insert the new xattr entry. */ | 1688 | } |
1436 | le16_add_cpu(&xs->header->xh_count, 1); | 1689 | |
1437 | ocfs2_xattr_set_type(last, xi->name_index); | 1690 | static void ocfs2_xa_bucket_journal_dirty(handle_t *handle, |
1438 | ocfs2_xattr_set_local(last, 1); | 1691 | struct ocfs2_xa_loc *loc) |
1439 | last->xe_name_len = name_len; | 1692 | { |
1440 | } else { | 1693 | struct ocfs2_xattr_bucket *bucket = loc->xl_storage; |
1441 | void *first_val; | 1694 | |
1442 | void *val; | 1695 | ocfs2_xattr_bucket_journal_dirty(handle, bucket); |
1443 | size_t offs, size; | 1696 | } |
1444 | 1697 | ||
1445 | first_val = xs->base + min_offs; | 1698 | static void *ocfs2_xa_bucket_offset_pointer(struct ocfs2_xa_loc *loc, |
1446 | offs = le16_to_cpu(xs->here->xe_name_offset); | 1699 | int offset) |
1447 | val = xs->base + offs; | 1700 | { |
1448 | 1701 | struct ocfs2_xattr_bucket *bucket = loc->xl_storage; | |
1449 | if (le64_to_cpu(xs->here->xe_value_size) > | 1702 | int block, block_offset; |
1450 | OCFS2_XATTR_INLINE_SIZE) | 1703 | |
1451 | size = OCFS2_XATTR_SIZE(name_len) + | 1704 | /* The header is at the front of the bucket */ |
1452 | OCFS2_XATTR_ROOT_SIZE; | 1705 | block = offset >> loc->xl_inode->i_sb->s_blocksize_bits; |
1706 | block_offset = offset % loc->xl_inode->i_sb->s_blocksize; | ||
1707 | |||
1708 | return bucket_block(bucket, block) + block_offset; | ||
1709 | } | ||
1710 | |||
1711 | static int ocfs2_xa_bucket_can_reuse(struct ocfs2_xa_loc *loc, | ||
1712 | struct ocfs2_xattr_info *xi) | ||
1713 | { | ||
1714 | return namevalue_size_xe(loc->xl_entry) >= | ||
1715 | namevalue_size_xi(xi); | ||
1716 | } | ||
1717 | |||
1718 | static int ocfs2_xa_bucket_get_free_start(struct ocfs2_xa_loc *loc) | ||
1719 | { | ||
1720 | struct ocfs2_xattr_bucket *bucket = loc->xl_storage; | ||
1721 | return le16_to_cpu(bucket_xh(bucket)->xh_free_start); | ||
1722 | } | ||
1723 | |||
1724 | static int ocfs2_bucket_align_free_start(struct super_block *sb, | ||
1725 | int free_start, int size) | ||
1726 | { | ||
1727 | /* | ||
1728 | * We need to make sure that the name+value pair fits within | ||
1729 | * one block. | ||
1730 | */ | ||
1731 | if (((free_start - size) >> sb->s_blocksize_bits) != | ||
1732 | ((free_start - 1) >> sb->s_blocksize_bits)) | ||
1733 | free_start -= free_start % sb->s_blocksize; | ||
1734 | |||
1735 | return free_start; | ||
1736 | } | ||
1737 | |||
1738 | static int ocfs2_xa_bucket_check_space(struct ocfs2_xa_loc *loc, | ||
1739 | struct ocfs2_xattr_info *xi) | ||
1740 | { | ||
1741 | int rc; | ||
1742 | int count = le16_to_cpu(loc->xl_header->xh_count); | ||
1743 | int free_start = ocfs2_xa_get_free_start(loc); | ||
1744 | int needed_space = ocfs2_xi_entry_usage(xi); | ||
1745 | int size = namevalue_size_xi(xi); | ||
1746 | struct super_block *sb = loc->xl_inode->i_sb; | ||
1747 | |||
1748 | /* | ||
1749 | * Bucket storage does not reclaim name+value pairs it cannot | ||
1750 | * reuse. They live as holes until the bucket fills, and then | ||
1751 | * the bucket is defragmented. However, the bucket can reclaim | ||
1752 | * the ocfs2_xattr_entry. | ||
1753 | */ | ||
1754 | if (loc->xl_entry) { | ||
1755 | /* Don't need space if we're reusing! */ | ||
1756 | if (ocfs2_xa_can_reuse_entry(loc, xi)) | ||
1757 | needed_space = 0; | ||
1453 | else | 1758 | else |
1454 | size = OCFS2_XATTR_SIZE(name_len) + | 1759 | needed_space -= sizeof(struct ocfs2_xattr_entry); |
1455 | OCFS2_XATTR_SIZE(le64_to_cpu(xs->here->xe_value_size)); | 1760 | } |
1456 | 1761 | BUG_ON(needed_space < 0); | |
1457 | if (xi->value && size == OCFS2_XATTR_SIZE(name_len) + | ||
1458 | OCFS2_XATTR_SIZE(xi->value_len)) { | ||
1459 | /* The old and the new value have the | ||
1460 | same size. Just replace the value. */ | ||
1461 | ocfs2_xattr_set_local(xs->here, 1); | ||
1462 | xs->here->xe_value_size = cpu_to_le64(xi->value_len); | ||
1463 | /* Clear value bytes. */ | ||
1464 | memset(val + OCFS2_XATTR_SIZE(name_len), | ||
1465 | 0, | ||
1466 | OCFS2_XATTR_SIZE(xi->value_len)); | ||
1467 | memcpy(val + OCFS2_XATTR_SIZE(name_len), | ||
1468 | xi->value, | ||
1469 | xi->value_len); | ||
1470 | return; | ||
1471 | } | ||
1472 | /* Remove the old name+value. */ | ||
1473 | memmove(first_val + size, first_val, val - first_val); | ||
1474 | memset(first_val, 0, size); | ||
1475 | xs->here->xe_name_hash = 0; | ||
1476 | xs->here->xe_name_offset = 0; | ||
1477 | ocfs2_xattr_set_local(xs->here, 1); | ||
1478 | xs->here->xe_value_size = 0; | ||
1479 | |||
1480 | min_offs += size; | ||
1481 | |||
1482 | /* Adjust all value offsets. */ | ||
1483 | last = xs->header->xh_entries; | ||
1484 | for (i = 0 ; i < le16_to_cpu(xs->header->xh_count); i++) { | ||
1485 | size_t o = le16_to_cpu(last->xe_name_offset); | ||
1486 | |||
1487 | if (o < offs) | ||
1488 | last->xe_name_offset = cpu_to_le16(o + size); | ||
1489 | last += 1; | ||
1490 | } | ||
1491 | 1762 | ||
1492 | if (!xi->value) { | 1763 | if (free_start < size) { |
1493 | /* Remove the old entry. */ | 1764 | if (needed_space) |
1494 | last -= 1; | 1765 | return -ENOSPC; |
1495 | memmove(xs->here, xs->here + 1, | 1766 | } else { |
1496 | (void *)last - (void *)xs->here); | 1767 | /* |
1497 | memset(last, 0, sizeof(struct ocfs2_xattr_entry)); | 1768 | * First we check if it would fit in the first place. |
1498 | le16_add_cpu(&xs->header->xh_count, -1); | 1769 | * Below, we align the free start to a block. This may |
1499 | } | 1770 | * slide us below the minimum gap. By checking unaligned |
1771 | * first, we avoid that error. | ||
1772 | */ | ||
1773 | rc = ocfs2_xa_check_space_helper(needed_space, free_start, | ||
1774 | count); | ||
1775 | if (rc) | ||
1776 | return rc; | ||
1777 | free_start = ocfs2_bucket_align_free_start(sb, free_start, | ||
1778 | size); | ||
1500 | } | 1779 | } |
1501 | if (xi->value) { | 1780 | return ocfs2_xa_check_space_helper(needed_space, free_start, count); |
1502 | /* Insert the new name+value. */ | 1781 | } |
1503 | size_t size = OCFS2_XATTR_SIZE(name_len) + | 1782 | |
1504 | OCFS2_XATTR_SIZE(xi->value_len); | 1783 | static void ocfs2_xa_bucket_wipe_namevalue(struct ocfs2_xa_loc *loc) |
1505 | void *val = xs->base + min_offs - size; | 1784 | { |
1785 | le16_add_cpu(&loc->xl_header->xh_name_value_len, | ||
1786 | -namevalue_size_xe(loc->xl_entry)); | ||
1787 | } | ||
1506 | 1788 | ||
1507 | xs->here->xe_name_offset = cpu_to_le16(min_offs - size); | 1789 | static void ocfs2_xa_bucket_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash) |
1508 | memset(val, 0, size); | 1790 | { |
1509 | memcpy(val, xi->name, name_len); | 1791 | struct ocfs2_xattr_header *xh = loc->xl_header; |
1510 | memcpy(val + OCFS2_XATTR_SIZE(name_len), | 1792 | int count = le16_to_cpu(xh->xh_count); |
1511 | xi->value, | 1793 | int low = 0, high = count - 1, tmp; |
1512 | xi->value_len); | 1794 | struct ocfs2_xattr_entry *tmp_xe; |
1513 | xs->here->xe_value_size = cpu_to_le64(xi->value_len); | 1795 | |
1514 | ocfs2_xattr_set_local(xs->here, 1); | 1796 | /* |
1515 | ocfs2_xattr_hash_entry(inode, xs->header, xs->here); | 1797 | * We keep buckets sorted by name_hash, so we need to find |
1798 | * our insert place. | ||
1799 | */ | ||
1800 | while (low <= high && count) { | ||
1801 | tmp = (low + high) / 2; | ||
1802 | tmp_xe = &xh->xh_entries[tmp]; | ||
1803 | |||
1804 | if (name_hash > le32_to_cpu(tmp_xe->xe_name_hash)) | ||
1805 | low = tmp + 1; | ||
1806 | else if (name_hash < le32_to_cpu(tmp_xe->xe_name_hash)) | ||
1807 | high = tmp - 1; | ||
1808 | else { | ||
1809 | low = tmp; | ||
1810 | break; | ||
1811 | } | ||
1516 | } | 1812 | } |
1517 | 1813 | ||
1518 | return; | 1814 | if (low != count) |
1815 | memmove(&xh->xh_entries[low + 1], | ||
1816 | &xh->xh_entries[low], | ||
1817 | ((count - low) * sizeof(struct ocfs2_xattr_entry))); | ||
1818 | |||
1819 | le16_add_cpu(&xh->xh_count, 1); | ||
1820 | loc->xl_entry = &xh->xh_entries[low]; | ||
1821 | memset(loc->xl_entry, 0, sizeof(struct ocfs2_xattr_entry)); | ||
1822 | } | ||
1823 | |||
1824 | static void ocfs2_xa_bucket_add_namevalue(struct ocfs2_xa_loc *loc, int size) | ||
1825 | { | ||
1826 | int free_start = ocfs2_xa_get_free_start(loc); | ||
1827 | struct ocfs2_xattr_header *xh = loc->xl_header; | ||
1828 | struct super_block *sb = loc->xl_inode->i_sb; | ||
1829 | int nameval_offset; | ||
1830 | |||
1831 | free_start = ocfs2_bucket_align_free_start(sb, free_start, size); | ||
1832 | nameval_offset = free_start - size; | ||
1833 | loc->xl_entry->xe_name_offset = cpu_to_le16(nameval_offset); | ||
1834 | xh->xh_free_start = cpu_to_le16(nameval_offset); | ||
1835 | le16_add_cpu(&xh->xh_name_value_len, size); | ||
1836 | |||
1837 | } | ||
1838 | |||
1839 | static void ocfs2_xa_bucket_fill_value_buf(struct ocfs2_xa_loc *loc, | ||
1840 | struct ocfs2_xattr_value_buf *vb) | ||
1841 | { | ||
1842 | struct ocfs2_xattr_bucket *bucket = loc->xl_storage; | ||
1843 | struct super_block *sb = loc->xl_inode->i_sb; | ||
1844 | int nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset); | ||
1845 | int size = namevalue_size_xe(loc->xl_entry); | ||
1846 | int block_offset = nameval_offset >> sb->s_blocksize_bits; | ||
1847 | |||
1848 | /* Values are not allowed to straddle block boundaries */ | ||
1849 | BUG_ON(block_offset != | ||
1850 | ((nameval_offset + size - 1) >> sb->s_blocksize_bits)); | ||
1851 | /* We expect the bucket to be filled in */ | ||
1852 | BUG_ON(!bucket->bu_bhs[block_offset]); | ||
1853 | |||
1854 | vb->vb_access = ocfs2_journal_access; | ||
1855 | vb->vb_bh = bucket->bu_bhs[block_offset]; | ||
1856 | } | ||
1857 | |||
1858 | /* Operations for xattrs stored in buckets. */ | ||
1859 | static const struct ocfs2_xa_loc_operations ocfs2_xa_bucket_loc_ops = { | ||
1860 | .xlo_journal_access = ocfs2_xa_bucket_journal_access, | ||
1861 | .xlo_journal_dirty = ocfs2_xa_bucket_journal_dirty, | ||
1862 | .xlo_offset_pointer = ocfs2_xa_bucket_offset_pointer, | ||
1863 | .xlo_check_space = ocfs2_xa_bucket_check_space, | ||
1864 | .xlo_can_reuse = ocfs2_xa_bucket_can_reuse, | ||
1865 | .xlo_get_free_start = ocfs2_xa_bucket_get_free_start, | ||
1866 | .xlo_wipe_namevalue = ocfs2_xa_bucket_wipe_namevalue, | ||
1867 | .xlo_add_entry = ocfs2_xa_bucket_add_entry, | ||
1868 | .xlo_add_namevalue = ocfs2_xa_bucket_add_namevalue, | ||
1869 | .xlo_fill_value_buf = ocfs2_xa_bucket_fill_value_buf, | ||
1870 | }; | ||
1871 | |||
1872 | static unsigned int ocfs2_xa_value_clusters(struct ocfs2_xa_loc *loc) | ||
1873 | { | ||
1874 | struct ocfs2_xattr_value_buf vb; | ||
1875 | |||
1876 | if (ocfs2_xattr_is_local(loc->xl_entry)) | ||
1877 | return 0; | ||
1878 | |||
1879 | ocfs2_xa_fill_value_buf(loc, &vb); | ||
1880 | return le32_to_cpu(vb.vb_xv->xr_clusters); | ||
1881 | } | ||
1882 | |||
1883 | static int ocfs2_xa_value_truncate(struct ocfs2_xa_loc *loc, u64 bytes, | ||
1884 | struct ocfs2_xattr_set_ctxt *ctxt) | ||
1885 | { | ||
1886 | int trunc_rc, access_rc; | ||
1887 | struct ocfs2_xattr_value_buf vb; | ||
1888 | |||
1889 | ocfs2_xa_fill_value_buf(loc, &vb); | ||
1890 | trunc_rc = ocfs2_xattr_value_truncate(loc->xl_inode, &vb, bytes, | ||
1891 | ctxt); | ||
1892 | |||
1893 | /* | ||
1894 | * The caller of ocfs2_xa_value_truncate() has already called | ||
1895 | * ocfs2_xa_journal_access on the loc. However, The truncate code | ||
1896 | * calls ocfs2_extend_trans(). This may commit the previous | ||
1897 | * transaction and open a new one. If this is a bucket, truncate | ||
1898 | * could leave only vb->vb_bh set up for journaling. Meanwhile, | ||
1899 | * the caller is expecting to dirty the entire bucket. So we must | ||
1900 | * reset the journal work. We do this even if truncate has failed, | ||
1901 | * as it could have failed after committing the extend. | ||
1902 | */ | ||
1903 | access_rc = ocfs2_xa_journal_access(ctxt->handle, loc, | ||
1904 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
1905 | |||
1906 | /* Errors in truncate take precedence */ | ||
1907 | return trunc_rc ? trunc_rc : access_rc; | ||
1908 | } | ||
1909 | |||
1910 | static void ocfs2_xa_remove_entry(struct ocfs2_xa_loc *loc) | ||
1911 | { | ||
1912 | int index, count; | ||
1913 | struct ocfs2_xattr_header *xh = loc->xl_header; | ||
1914 | struct ocfs2_xattr_entry *entry = loc->xl_entry; | ||
1915 | |||
1916 | ocfs2_xa_wipe_namevalue(loc); | ||
1917 | loc->xl_entry = NULL; | ||
1918 | |||
1919 | le16_add_cpu(&xh->xh_count, -1); | ||
1920 | count = le16_to_cpu(xh->xh_count); | ||
1921 | |||
1922 | /* | ||
1923 | * Only zero out the entry if there are more remaining. This is | ||
1924 | * important for an empty bucket, as it keeps track of the | ||
1925 | * bucket's hash value. It doesn't hurt empty block storage. | ||
1926 | */ | ||
1927 | if (count) { | ||
1928 | index = ((char *)entry - (char *)&xh->xh_entries) / | ||
1929 | sizeof(struct ocfs2_xattr_entry); | ||
1930 | memmove(&xh->xh_entries[index], &xh->xh_entries[index + 1], | ||
1931 | (count - index) * sizeof(struct ocfs2_xattr_entry)); | ||
1932 | memset(&xh->xh_entries[count], 0, | ||
1933 | sizeof(struct ocfs2_xattr_entry)); | ||
1934 | } | ||
1519 | } | 1935 | } |
1520 | 1936 | ||
1521 | /* | 1937 | /* |
1522 | * ocfs2_xattr_set_entry() | 1938 | * If we have a problem adjusting the size of an external value during |
1939 | * ocfs2_xa_prepare_entry() or ocfs2_xa_remove(), we may have an xattr | ||
1940 | * in an intermediate state. For example, the value may be partially | ||
1941 | * truncated. | ||
1942 | * | ||
1943 | * If the value tree hasn't changed, the extend/truncate went nowhere. | ||
1944 | * We have nothing to do. The caller can treat it as a straight error. | ||
1523 | * | 1945 | * |
1524 | * Set extended attribute entry into inode or block. | 1946 | * If the value tree got partially truncated, we now have a corrupted |
1947 | * extended attribute. We're going to wipe its entry and leak the | ||
1948 | * clusters. Better to leak some storage than leave a corrupt entry. | ||
1525 | * | 1949 | * |
1526 | * If extended attribute value size > OCFS2_XATTR_INLINE_SIZE, | 1950 | * If the value tree grew, it obviously didn't grow enough for the |
1527 | * We first insert tree root(ocfs2_xattr_value_root) with set_entry_local(), | 1951 | * new entry. We're not going to try and reclaim those clusters either. |
1528 | * then set value in B tree with set_value_outside(). | 1952 | * If there was already an external value there (orig_clusters != 0), |
1953 | * the new clusters are attached safely and we can just leave the old | ||
1954 | * value in place. If there was no external value there, we remove | ||
1955 | * the entry. | ||
1956 | * | ||
1957 | * This way, the xattr block we store in the journal will be consistent. | ||
1958 | * If the size change broke because of the journal, no changes will hit | ||
1959 | * disk anyway. | ||
1529 | */ | 1960 | */ |
1530 | static int ocfs2_xattr_set_entry(struct inode *inode, | 1961 | static void ocfs2_xa_cleanup_value_truncate(struct ocfs2_xa_loc *loc, |
1531 | struct ocfs2_xattr_info *xi, | 1962 | const char *what, |
1532 | struct ocfs2_xattr_search *xs, | 1963 | unsigned int orig_clusters) |
1533 | struct ocfs2_xattr_set_ctxt *ctxt, | 1964 | { |
1534 | int flag) | 1965 | unsigned int new_clusters = ocfs2_xa_value_clusters(loc); |
1535 | { | 1966 | char *nameval_buf = ocfs2_xa_offset_pointer(loc, |
1536 | struct ocfs2_xattr_entry *last; | 1967 | le16_to_cpu(loc->xl_entry->xe_name_offset)); |
1537 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | 1968 | |
1538 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; | 1969 | if (new_clusters < orig_clusters) { |
1539 | size_t min_offs = xs->end - xs->base, name_len = strlen(xi->name); | 1970 | mlog(ML_ERROR, |
1540 | size_t size_l = 0; | 1971 | "Partial truncate while %s xattr %.*s. Leaking " |
1541 | handle_t *handle = ctxt->handle; | 1972 | "%u clusters and removing the entry\n", |
1542 | int free, i, ret; | 1973 | what, loc->xl_entry->xe_name_len, nameval_buf, |
1543 | struct ocfs2_xattr_info xi_l = { | 1974 | orig_clusters - new_clusters); |
1544 | .name_index = xi->name_index, | 1975 | ocfs2_xa_remove_entry(loc); |
1545 | .name = xi->name, | 1976 | } else if (!orig_clusters) { |
1546 | .value = xi->value, | 1977 | mlog(ML_ERROR, |
1547 | .value_len = xi->value_len, | 1978 | "Unable to allocate an external value for xattr " |
1548 | }; | 1979 | "%.*s safely. Leaking %u clusters and removing the " |
1549 | struct ocfs2_xattr_value_buf vb = { | 1980 | "entry\n", |
1550 | .vb_bh = xs->xattr_bh, | 1981 | loc->xl_entry->xe_name_len, nameval_buf, |
1551 | .vb_access = ocfs2_journal_access_di, | 1982 | new_clusters - orig_clusters); |
1552 | }; | 1983 | ocfs2_xa_remove_entry(loc); |
1984 | } else if (new_clusters > orig_clusters) | ||
1985 | mlog(ML_ERROR, | ||
1986 | "Unable to grow xattr %.*s safely. %u new clusters " | ||
1987 | "have been added, but the value will not be " | ||
1988 | "modified\n", | ||
1989 | loc->xl_entry->xe_name_len, nameval_buf, | ||
1990 | new_clusters - orig_clusters); | ||
1991 | } | ||
1992 | |||
1993 | static int ocfs2_xa_remove(struct ocfs2_xa_loc *loc, | ||
1994 | struct ocfs2_xattr_set_ctxt *ctxt) | ||
1995 | { | ||
1996 | int rc = 0; | ||
1997 | unsigned int orig_clusters; | ||
1998 | |||
1999 | if (!ocfs2_xattr_is_local(loc->xl_entry)) { | ||
2000 | orig_clusters = ocfs2_xa_value_clusters(loc); | ||
2001 | rc = ocfs2_xa_value_truncate(loc, 0, ctxt); | ||
2002 | if (rc) { | ||
2003 | mlog_errno(rc); | ||
2004 | /* | ||
2005 | * Since this is remove, we can return 0 if | ||
2006 | * ocfs2_xa_cleanup_value_truncate() is going to | ||
2007 | * wipe the entry anyway. So we check the | ||
2008 | * cluster count as well. | ||
2009 | */ | ||
2010 | if (orig_clusters != ocfs2_xa_value_clusters(loc)) | ||
2011 | rc = 0; | ||
2012 | ocfs2_xa_cleanup_value_truncate(loc, "removing", | ||
2013 | orig_clusters); | ||
2014 | if (rc) | ||
2015 | goto out; | ||
2016 | } | ||
2017 | } | ||
1553 | 2018 | ||
1554 | if (!(flag & OCFS2_INLINE_XATTR_FL)) { | 2019 | ocfs2_xa_remove_entry(loc); |
1555 | BUG_ON(xs->xattr_bh == xs->inode_bh); | ||
1556 | vb.vb_access = ocfs2_journal_access_xb; | ||
1557 | } else | ||
1558 | BUG_ON(xs->xattr_bh != xs->inode_bh); | ||
1559 | 2020 | ||
1560 | /* Compute min_offs, last and free space. */ | 2021 | out: |
1561 | last = xs->header->xh_entries; | 2022 | return rc; |
2023 | } | ||
1562 | 2024 | ||
1563 | for (i = 0 ; i < le16_to_cpu(xs->header->xh_count); i++) { | 2025 | static void ocfs2_xa_install_value_root(struct ocfs2_xa_loc *loc) |
1564 | size_t offs = le16_to_cpu(last->xe_name_offset); | 2026 | { |
1565 | if (offs < min_offs) | 2027 | int name_size = OCFS2_XATTR_SIZE(loc->xl_entry->xe_name_len); |
1566 | min_offs = offs; | 2028 | char *nameval_buf; |
1567 | last += 1; | ||
1568 | } | ||
1569 | 2029 | ||
1570 | free = min_offs - ((void *)last - xs->base) - OCFS2_XATTR_HEADER_GAP; | 2030 | nameval_buf = ocfs2_xa_offset_pointer(loc, |
1571 | if (free < 0) | 2031 | le16_to_cpu(loc->xl_entry->xe_name_offset)); |
1572 | return -EIO; | 2032 | memcpy(nameval_buf + name_size, &def_xv, OCFS2_XATTR_ROOT_SIZE); |
2033 | } | ||
1573 | 2034 | ||
1574 | if (!xs->not_found) { | 2035 | /* |
1575 | size_t size = 0; | 2036 | * Take an existing entry and make it ready for the new value. This |
1576 | if (ocfs2_xattr_is_local(xs->here)) | 2037 | * won't allocate space, but it may free space. It should be ready for |
1577 | size = OCFS2_XATTR_SIZE(name_len) + | 2038 | * ocfs2_xa_prepare_entry() to finish the work. |
1578 | OCFS2_XATTR_SIZE(le64_to_cpu(xs->here->xe_value_size)); | 2039 | */ |
1579 | else | 2040 | static int ocfs2_xa_reuse_entry(struct ocfs2_xa_loc *loc, |
1580 | size = OCFS2_XATTR_SIZE(name_len) + | 2041 | struct ocfs2_xattr_info *xi, |
1581 | OCFS2_XATTR_ROOT_SIZE; | 2042 | struct ocfs2_xattr_set_ctxt *ctxt) |
1582 | free += (size + sizeof(struct ocfs2_xattr_entry)); | 2043 | { |
1583 | } | 2044 | int rc = 0; |
1584 | /* Check free space in inode or block */ | 2045 | int name_size = OCFS2_XATTR_SIZE(xi->xi_name_len); |
1585 | if (xi->value && xi->value_len > OCFS2_XATTR_INLINE_SIZE) { | 2046 | unsigned int orig_clusters; |
1586 | if (free < sizeof(struct ocfs2_xattr_entry) + | 2047 | char *nameval_buf; |
1587 | OCFS2_XATTR_SIZE(name_len) + | 2048 | int xe_local = ocfs2_xattr_is_local(loc->xl_entry); |
1588 | OCFS2_XATTR_ROOT_SIZE) { | 2049 | int xi_local = xi->xi_value_len <= OCFS2_XATTR_INLINE_SIZE; |
1589 | ret = -ENOSPC; | 2050 | |
1590 | goto out; | 2051 | BUG_ON(OCFS2_XATTR_SIZE(loc->xl_entry->xe_name_len) != |
2052 | name_size); | ||
2053 | |||
2054 | nameval_buf = ocfs2_xa_offset_pointer(loc, | ||
2055 | le16_to_cpu(loc->xl_entry->xe_name_offset)); | ||
2056 | if (xe_local) { | ||
2057 | memset(nameval_buf + name_size, 0, | ||
2058 | namevalue_size_xe(loc->xl_entry) - name_size); | ||
2059 | if (!xi_local) | ||
2060 | ocfs2_xa_install_value_root(loc); | ||
2061 | } else { | ||
2062 | orig_clusters = ocfs2_xa_value_clusters(loc); | ||
2063 | if (xi_local) { | ||
2064 | rc = ocfs2_xa_value_truncate(loc, 0, ctxt); | ||
2065 | if (rc < 0) | ||
2066 | mlog_errno(rc); | ||
2067 | else | ||
2068 | memset(nameval_buf + name_size, 0, | ||
2069 | namevalue_size_xe(loc->xl_entry) - | ||
2070 | name_size); | ||
2071 | } else if (le64_to_cpu(loc->xl_entry->xe_value_size) > | ||
2072 | xi->xi_value_len) { | ||
2073 | rc = ocfs2_xa_value_truncate(loc, xi->xi_value_len, | ||
2074 | ctxt); | ||
2075 | if (rc < 0) | ||
2076 | mlog_errno(rc); | ||
1591 | } | 2077 | } |
1592 | size_l = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_ROOT_SIZE; | 2078 | |
1593 | xi_l.value = (void *)&def_xv; | 2079 | if (rc) { |
1594 | xi_l.value_len = OCFS2_XATTR_ROOT_SIZE; | 2080 | ocfs2_xa_cleanup_value_truncate(loc, "reusing", |
1595 | } else if (xi->value) { | 2081 | orig_clusters); |
1596 | if (free < sizeof(struct ocfs2_xattr_entry) + | ||
1597 | OCFS2_XATTR_SIZE(name_len) + | ||
1598 | OCFS2_XATTR_SIZE(xi->value_len)) { | ||
1599 | ret = -ENOSPC; | ||
1600 | goto out; | 2082 | goto out; |
1601 | } | 2083 | } |
1602 | } | 2084 | } |
1603 | 2085 | ||
1604 | if (!xs->not_found) { | 2086 | loc->xl_entry->xe_value_size = cpu_to_le64(xi->xi_value_len); |
1605 | /* For existing extended attribute */ | 2087 | ocfs2_xattr_set_local(loc->xl_entry, xi_local); |
1606 | size_t size = OCFS2_XATTR_SIZE(name_len) + | ||
1607 | OCFS2_XATTR_SIZE(le64_to_cpu(xs->here->xe_value_size)); | ||
1608 | size_t offs = le16_to_cpu(xs->here->xe_name_offset); | ||
1609 | void *val = xs->base + offs; | ||
1610 | 2088 | ||
1611 | if (ocfs2_xattr_is_local(xs->here) && size == size_l) { | 2089 | out: |
1612 | /* Replace existing local xattr with tree root */ | 2090 | return rc; |
1613 | ret = ocfs2_xattr_set_value_outside(inode, xi, xs, | 2091 | } |
1614 | ctxt, &vb, offs); | ||
1615 | if (ret < 0) | ||
1616 | mlog_errno(ret); | ||
1617 | goto out; | ||
1618 | } else if (!ocfs2_xattr_is_local(xs->here)) { | ||
1619 | /* For existing xattr which has value outside */ | ||
1620 | vb.vb_xv = (struct ocfs2_xattr_value_root *) | ||
1621 | (val + OCFS2_XATTR_SIZE(name_len)); | ||
1622 | 2092 | ||
1623 | if (xi->value_len > OCFS2_XATTR_INLINE_SIZE) { | 2093 | /* |
1624 | /* | 2094 | * Prepares loc->xl_entry to receive the new xattr. This includes |
1625 | * If new value need set outside also, | 2095 | * properly setting up the name+value pair region. If loc->xl_entry |
1626 | * first truncate old value to new value, | 2096 | * already exists, it will take care of modifying it appropriately. |
1627 | * then set new value with set_value_outside(). | 2097 | * |
1628 | */ | 2098 | * Note that this modifies the data. You did journal_access already, |
1629 | ret = ocfs2_xattr_value_truncate(inode, | 2099 | * right? |
1630 | &vb, | 2100 | */ |
1631 | xi->value_len, | 2101 | static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc, |
1632 | ctxt); | 2102 | struct ocfs2_xattr_info *xi, |
1633 | if (ret < 0) { | 2103 | u32 name_hash, |
1634 | mlog_errno(ret); | 2104 | struct ocfs2_xattr_set_ctxt *ctxt) |
1635 | goto out; | 2105 | { |
1636 | } | 2106 | int rc = 0; |
2107 | unsigned int orig_clusters; | ||
2108 | __le64 orig_value_size = 0; | ||
1637 | 2109 | ||
1638 | ret = ocfs2_xattr_update_entry(inode, | 2110 | rc = ocfs2_xa_check_space(loc, xi); |
1639 | handle, | 2111 | if (rc) |
1640 | xi, | 2112 | goto out; |
1641 | xs, | ||
1642 | &vb, | ||
1643 | offs); | ||
1644 | if (ret < 0) { | ||
1645 | mlog_errno(ret); | ||
1646 | goto out; | ||
1647 | } | ||
1648 | 2113 | ||
1649 | ret = __ocfs2_xattr_set_value_outside(inode, | 2114 | if (loc->xl_entry) { |
1650 | handle, | 2115 | if (ocfs2_xa_can_reuse_entry(loc, xi)) { |
1651 | &vb, | 2116 | orig_value_size = loc->xl_entry->xe_value_size; |
1652 | xi->value, | 2117 | rc = ocfs2_xa_reuse_entry(loc, xi, ctxt); |
1653 | xi->value_len); | 2118 | if (rc) |
1654 | if (ret < 0) | 2119 | goto out; |
1655 | mlog_errno(ret); | 2120 | goto alloc_value; |
2121 | } | ||
2122 | |||
2123 | if (!ocfs2_xattr_is_local(loc->xl_entry)) { | ||
2124 | orig_clusters = ocfs2_xa_value_clusters(loc); | ||
2125 | rc = ocfs2_xa_value_truncate(loc, 0, ctxt); | ||
2126 | if (rc) { | ||
2127 | mlog_errno(rc); | ||
2128 | ocfs2_xa_cleanup_value_truncate(loc, | ||
2129 | "overwriting", | ||
2130 | orig_clusters); | ||
1656 | goto out; | 2131 | goto out; |
1657 | } else { | ||
1658 | /* | ||
1659 | * If new value need set in local, | ||
1660 | * just trucate old value to zero. | ||
1661 | */ | ||
1662 | ret = ocfs2_xattr_value_truncate(inode, | ||
1663 | &vb, | ||
1664 | 0, | ||
1665 | ctxt); | ||
1666 | if (ret < 0) | ||
1667 | mlog_errno(ret); | ||
1668 | } | 2132 | } |
1669 | } | 2133 | } |
2134 | ocfs2_xa_wipe_namevalue(loc); | ||
2135 | } else | ||
2136 | ocfs2_xa_add_entry(loc, name_hash); | ||
2137 | |||
2138 | /* | ||
2139 | * If we get here, we have a blank entry. Fill it. We grow our | ||
2140 | * name+value pair back from the end. | ||
2141 | */ | ||
2142 | ocfs2_xa_add_namevalue(loc, xi); | ||
2143 | if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) | ||
2144 | ocfs2_xa_install_value_root(loc); | ||
2145 | |||
2146 | alloc_value: | ||
2147 | if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) { | ||
2148 | orig_clusters = ocfs2_xa_value_clusters(loc); | ||
2149 | rc = ocfs2_xa_value_truncate(loc, xi->xi_value_len, ctxt); | ||
2150 | if (rc < 0) { | ||
2151 | /* | ||
2152 | * If we tried to grow an existing external value, | ||
2153 | * ocfs2_xa_cleanuP-value_truncate() is going to | ||
2154 | * let it stand. We have to restore its original | ||
2155 | * value size. | ||
2156 | */ | ||
2157 | loc->xl_entry->xe_value_size = orig_value_size; | ||
2158 | ocfs2_xa_cleanup_value_truncate(loc, "growing", | ||
2159 | orig_clusters); | ||
2160 | mlog_errno(rc); | ||
2161 | } | ||
1670 | } | 2162 | } |
1671 | 2163 | ||
1672 | ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), xs->inode_bh, | 2164 | out: |
2165 | return rc; | ||
2166 | } | ||
2167 | |||
2168 | /* | ||
2169 | * Store the value portion of the name+value pair. This will skip | ||
2170 | * values that are stored externally. Their tree roots were set up | ||
2171 | * by ocfs2_xa_prepare_entry(). | ||
2172 | */ | ||
2173 | static int ocfs2_xa_store_value(struct ocfs2_xa_loc *loc, | ||
2174 | struct ocfs2_xattr_info *xi, | ||
2175 | struct ocfs2_xattr_set_ctxt *ctxt) | ||
2176 | { | ||
2177 | int rc = 0; | ||
2178 | int nameval_offset = le16_to_cpu(loc->xl_entry->xe_name_offset); | ||
2179 | int name_size = OCFS2_XATTR_SIZE(xi->xi_name_len); | ||
2180 | char *nameval_buf; | ||
2181 | struct ocfs2_xattr_value_buf vb; | ||
2182 | |||
2183 | nameval_buf = ocfs2_xa_offset_pointer(loc, nameval_offset); | ||
2184 | if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) { | ||
2185 | ocfs2_xa_fill_value_buf(loc, &vb); | ||
2186 | rc = __ocfs2_xattr_set_value_outside(loc->xl_inode, | ||
2187 | ctxt->handle, &vb, | ||
2188 | xi->xi_value, | ||
2189 | xi->xi_value_len); | ||
2190 | } else | ||
2191 | memcpy(nameval_buf + name_size, xi->xi_value, xi->xi_value_len); | ||
2192 | |||
2193 | return rc; | ||
2194 | } | ||
2195 | |||
2196 | static int ocfs2_xa_set(struct ocfs2_xa_loc *loc, | ||
2197 | struct ocfs2_xattr_info *xi, | ||
2198 | struct ocfs2_xattr_set_ctxt *ctxt) | ||
2199 | { | ||
2200 | int ret; | ||
2201 | u32 name_hash = ocfs2_xattr_name_hash(loc->xl_inode, xi->xi_name, | ||
2202 | xi->xi_name_len); | ||
2203 | |||
2204 | ret = ocfs2_xa_journal_access(ctxt->handle, loc, | ||
1673 | OCFS2_JOURNAL_ACCESS_WRITE); | 2205 | OCFS2_JOURNAL_ACCESS_WRITE); |
1674 | if (ret) { | 2206 | if (ret) { |
1675 | mlog_errno(ret); | 2207 | mlog_errno(ret); |
1676 | goto out; | 2208 | goto out; |
1677 | } | 2209 | } |
1678 | 2210 | ||
1679 | if (!(flag & OCFS2_INLINE_XATTR_FL)) { | ||
1680 | ret = vb.vb_access(handle, INODE_CACHE(inode), vb.vb_bh, | ||
1681 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
1682 | if (ret) { | ||
1683 | mlog_errno(ret); | ||
1684 | goto out; | ||
1685 | } | ||
1686 | } | ||
1687 | |||
1688 | /* | 2211 | /* |
1689 | * Set value in local, include set tree root in local. | 2212 | * From here on out, everything is going to modify the buffer a |
1690 | * This is the first step for value size >INLINE_SIZE. | 2213 | * little. Errors are going to leave the xattr header in a |
2214 | * sane state. Thus, even with errors we dirty the sucker. | ||
1691 | */ | 2215 | */ |
1692 | ocfs2_xattr_set_entry_local(inode, &xi_l, xs, last, min_offs); | ||
1693 | 2216 | ||
1694 | if (!(flag & OCFS2_INLINE_XATTR_FL)) { | 2217 | /* Don't worry, we are never called with !xi_value and !xl_entry */ |
1695 | ret = ocfs2_journal_dirty(handle, xs->xattr_bh); | 2218 | if (!xi->xi_value) { |
1696 | if (ret < 0) { | 2219 | ret = ocfs2_xa_remove(loc, ctxt); |
1697 | mlog_errno(ret); | 2220 | goto out_dirty; |
1698 | goto out; | ||
1699 | } | ||
1700 | } | 2221 | } |
1701 | 2222 | ||
1702 | if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) && | 2223 | ret = ocfs2_xa_prepare_entry(loc, xi, name_hash, ctxt); |
1703 | (flag & OCFS2_INLINE_XATTR_FL)) { | 2224 | if (ret) { |
1704 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 2225 | if (ret != -ENOSPC) |
1705 | unsigned int xattrsize = osb->s_xattr_inline_size; | 2226 | mlog_errno(ret); |
1706 | 2227 | goto out_dirty; | |
1707 | /* | ||
1708 | * Adjust extent record count or inline data size | ||
1709 | * to reserve space for extended attribute. | ||
1710 | */ | ||
1711 | if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL) { | ||
1712 | struct ocfs2_inline_data *idata = &di->id2.i_data; | ||
1713 | le16_add_cpu(&idata->id_count, -xattrsize); | ||
1714 | } else if (!(ocfs2_inode_is_fast_symlink(inode))) { | ||
1715 | struct ocfs2_extent_list *el = &di->id2.i_list; | ||
1716 | le16_add_cpu(&el->l_count, -(xattrsize / | ||
1717 | sizeof(struct ocfs2_extent_rec))); | ||
1718 | } | ||
1719 | di->i_xattr_inline_size = cpu_to_le16(xattrsize); | ||
1720 | } | 2228 | } |
1721 | /* Update xattr flag */ | ||
1722 | spin_lock(&oi->ip_lock); | ||
1723 | oi->ip_dyn_features |= flag; | ||
1724 | di->i_dyn_features = cpu_to_le16(oi->ip_dyn_features); | ||
1725 | spin_unlock(&oi->ip_lock); | ||
1726 | 2229 | ||
1727 | ret = ocfs2_journal_dirty(handle, xs->inode_bh); | 2230 | ret = ocfs2_xa_store_value(loc, xi, ctxt); |
1728 | if (ret < 0) | 2231 | if (ret) |
1729 | mlog_errno(ret); | 2232 | mlog_errno(ret); |
1730 | 2233 | ||
1731 | if (!ret && xi->value_len > OCFS2_XATTR_INLINE_SIZE) { | 2234 | out_dirty: |
1732 | /* | 2235 | ocfs2_xa_journal_dirty(ctxt->handle, loc); |
1733 | * Set value outside in B tree. | ||
1734 | * This is the second step for value size > INLINE_SIZE. | ||
1735 | */ | ||
1736 | size_t offs = le16_to_cpu(xs->here->xe_name_offset); | ||
1737 | ret = ocfs2_xattr_set_value_outside(inode, xi, xs, ctxt, | ||
1738 | &vb, offs); | ||
1739 | if (ret < 0) { | ||
1740 | int ret2; | ||
1741 | 2236 | ||
1742 | mlog_errno(ret); | ||
1743 | /* | ||
1744 | * If set value outside failed, we have to clean | ||
1745 | * the junk tree root we have already set in local. | ||
1746 | */ | ||
1747 | ret2 = ocfs2_xattr_cleanup(inode, ctxt->handle, | ||
1748 | xi, xs, &vb, offs); | ||
1749 | if (ret2 < 0) | ||
1750 | mlog_errno(ret2); | ||
1751 | } | ||
1752 | } | ||
1753 | out: | 2237 | out: |
1754 | return ret; | 2238 | return ret; |
1755 | } | 2239 | } |
1756 | 2240 | ||
2241 | static void ocfs2_init_dinode_xa_loc(struct ocfs2_xa_loc *loc, | ||
2242 | struct inode *inode, | ||
2243 | struct buffer_head *bh, | ||
2244 | struct ocfs2_xattr_entry *entry) | ||
2245 | { | ||
2246 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data; | ||
2247 | |||
2248 | BUG_ON(!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_XATTR_FL)); | ||
2249 | |||
2250 | loc->xl_inode = inode; | ||
2251 | loc->xl_ops = &ocfs2_xa_block_loc_ops; | ||
2252 | loc->xl_storage = bh; | ||
2253 | loc->xl_entry = entry; | ||
2254 | loc->xl_size = le16_to_cpu(di->i_xattr_inline_size); | ||
2255 | loc->xl_header = | ||
2256 | (struct ocfs2_xattr_header *)(bh->b_data + bh->b_size - | ||
2257 | loc->xl_size); | ||
2258 | } | ||
2259 | |||
2260 | static void ocfs2_init_xattr_block_xa_loc(struct ocfs2_xa_loc *loc, | ||
2261 | struct inode *inode, | ||
2262 | struct buffer_head *bh, | ||
2263 | struct ocfs2_xattr_entry *entry) | ||
2264 | { | ||
2265 | struct ocfs2_xattr_block *xb = | ||
2266 | (struct ocfs2_xattr_block *)bh->b_data; | ||
2267 | |||
2268 | BUG_ON(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED); | ||
2269 | |||
2270 | loc->xl_inode = inode; | ||
2271 | loc->xl_ops = &ocfs2_xa_block_loc_ops; | ||
2272 | loc->xl_storage = bh; | ||
2273 | loc->xl_header = &(xb->xb_attrs.xb_header); | ||
2274 | loc->xl_entry = entry; | ||
2275 | loc->xl_size = bh->b_size - offsetof(struct ocfs2_xattr_block, | ||
2276 | xb_attrs.xb_header); | ||
2277 | } | ||
2278 | |||
2279 | static void ocfs2_init_xattr_bucket_xa_loc(struct ocfs2_xa_loc *loc, | ||
2280 | struct ocfs2_xattr_bucket *bucket, | ||
2281 | struct ocfs2_xattr_entry *entry) | ||
2282 | { | ||
2283 | loc->xl_inode = bucket->bu_inode; | ||
2284 | loc->xl_ops = &ocfs2_xa_bucket_loc_ops; | ||
2285 | loc->xl_storage = bucket; | ||
2286 | loc->xl_header = bucket_xh(bucket); | ||
2287 | loc->xl_entry = entry; | ||
2288 | loc->xl_size = OCFS2_XATTR_BUCKET_SIZE; | ||
2289 | } | ||
2290 | |||
1757 | /* | 2291 | /* |
1758 | * In xattr remove, if it is stored outside and refcounted, we may have | 2292 | * In xattr remove, if it is stored outside and refcounted, we may have |
1759 | * the chance to split the refcount tree. So need the allocators. | 2293 | * the chance to split the refcount tree. So need the allocators. |
@@ -2149,6 +2683,55 @@ static int ocfs2_xattr_ibody_find(struct inode *inode, | |||
2149 | return 0; | 2683 | return 0; |
2150 | } | 2684 | } |
2151 | 2685 | ||
2686 | static int ocfs2_xattr_ibody_init(struct inode *inode, | ||
2687 | struct buffer_head *di_bh, | ||
2688 | struct ocfs2_xattr_set_ctxt *ctxt) | ||
2689 | { | ||
2690 | int ret; | ||
2691 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | ||
2692 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
2693 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
2694 | unsigned int xattrsize = osb->s_xattr_inline_size; | ||
2695 | |||
2696 | if (!ocfs2_xattr_has_space_inline(inode, di)) { | ||
2697 | ret = -ENOSPC; | ||
2698 | goto out; | ||
2699 | } | ||
2700 | |||
2701 | ret = ocfs2_journal_access_di(ctxt->handle, INODE_CACHE(inode), di_bh, | ||
2702 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
2703 | if (ret) { | ||
2704 | mlog_errno(ret); | ||
2705 | goto out; | ||
2706 | } | ||
2707 | |||
2708 | /* | ||
2709 | * Adjust extent record count or inline data size | ||
2710 | * to reserve space for extended attribute. | ||
2711 | */ | ||
2712 | if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL) { | ||
2713 | struct ocfs2_inline_data *idata = &di->id2.i_data; | ||
2714 | le16_add_cpu(&idata->id_count, -xattrsize); | ||
2715 | } else if (!(ocfs2_inode_is_fast_symlink(inode))) { | ||
2716 | struct ocfs2_extent_list *el = &di->id2.i_list; | ||
2717 | le16_add_cpu(&el->l_count, -(xattrsize / | ||
2718 | sizeof(struct ocfs2_extent_rec))); | ||
2719 | } | ||
2720 | di->i_xattr_inline_size = cpu_to_le16(xattrsize); | ||
2721 | |||
2722 | spin_lock(&oi->ip_lock); | ||
2723 | oi->ip_dyn_features |= OCFS2_INLINE_XATTR_FL|OCFS2_HAS_XATTR_FL; | ||
2724 | di->i_dyn_features = cpu_to_le16(oi->ip_dyn_features); | ||
2725 | spin_unlock(&oi->ip_lock); | ||
2726 | |||
2727 | ret = ocfs2_journal_dirty(ctxt->handle, di_bh); | ||
2728 | if (ret < 0) | ||
2729 | mlog_errno(ret); | ||
2730 | |||
2731 | out: | ||
2732 | return ret; | ||
2733 | } | ||
2734 | |||
2152 | /* | 2735 | /* |
2153 | * ocfs2_xattr_ibody_set() | 2736 | * ocfs2_xattr_ibody_set() |
2154 | * | 2737 | * |
@@ -2160,9 +2743,10 @@ static int ocfs2_xattr_ibody_set(struct inode *inode, | |||
2160 | struct ocfs2_xattr_search *xs, | 2743 | struct ocfs2_xattr_search *xs, |
2161 | struct ocfs2_xattr_set_ctxt *ctxt) | 2744 | struct ocfs2_xattr_set_ctxt *ctxt) |
2162 | { | 2745 | { |
2746 | int ret; | ||
2163 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | 2747 | struct ocfs2_inode_info *oi = OCFS2_I(inode); |
2164 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; | 2748 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data; |
2165 | int ret; | 2749 | struct ocfs2_xa_loc loc; |
2166 | 2750 | ||
2167 | if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE) | 2751 | if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE) |
2168 | return -ENOSPC; | 2752 | return -ENOSPC; |
@@ -2175,8 +2759,25 @@ static int ocfs2_xattr_ibody_set(struct inode *inode, | |||
2175 | } | 2759 | } |
2176 | } | 2760 | } |
2177 | 2761 | ||
2178 | ret = ocfs2_xattr_set_entry(inode, xi, xs, ctxt, | 2762 | if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) { |
2179 | (OCFS2_INLINE_XATTR_FL | OCFS2_HAS_XATTR_FL)); | 2763 | ret = ocfs2_xattr_ibody_init(inode, xs->inode_bh, ctxt); |
2764 | if (ret) { | ||
2765 | if (ret != -ENOSPC) | ||
2766 | mlog_errno(ret); | ||
2767 | goto out; | ||
2768 | } | ||
2769 | } | ||
2770 | |||
2771 | ocfs2_init_dinode_xa_loc(&loc, inode, xs->inode_bh, | ||
2772 | xs->not_found ? NULL : xs->here); | ||
2773 | ret = ocfs2_xa_set(&loc, xi, ctxt); | ||
2774 | if (ret) { | ||
2775 | if (ret != -ENOSPC) | ||
2776 | mlog_errno(ret); | ||
2777 | goto out; | ||
2778 | } | ||
2779 | xs->here = loc.xl_entry; | ||
2780 | |||
2180 | out: | 2781 | out: |
2181 | up_write(&oi->ip_alloc_sem); | 2782 | up_write(&oi->ip_alloc_sem); |
2182 | 2783 | ||
@@ -2236,12 +2837,11 @@ cleanup: | |||
2236 | return ret; | 2837 | return ret; |
2237 | } | 2838 | } |
2238 | 2839 | ||
2239 | static int ocfs2_create_xattr_block(handle_t *handle, | 2840 | static int ocfs2_create_xattr_block(struct inode *inode, |
2240 | struct inode *inode, | ||
2241 | struct buffer_head *inode_bh, | 2841 | struct buffer_head *inode_bh, |
2242 | struct ocfs2_alloc_context *meta_ac, | 2842 | struct ocfs2_xattr_set_ctxt *ctxt, |
2243 | struct buffer_head **ret_bh, | 2843 | int indexed, |
2244 | int indexed) | 2844 | struct buffer_head **ret_bh) |
2245 | { | 2845 | { |
2246 | int ret; | 2846 | int ret; |
2247 | u16 suballoc_bit_start; | 2847 | u16 suballoc_bit_start; |
@@ -2252,14 +2852,14 @@ static int ocfs2_create_xattr_block(handle_t *handle, | |||
2252 | struct buffer_head *new_bh = NULL; | 2852 | struct buffer_head *new_bh = NULL; |
2253 | struct ocfs2_xattr_block *xblk; | 2853 | struct ocfs2_xattr_block *xblk; |
2254 | 2854 | ||
2255 | ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), inode_bh, | 2855 | ret = ocfs2_journal_access_di(ctxt->handle, INODE_CACHE(inode), |
2256 | OCFS2_JOURNAL_ACCESS_CREATE); | 2856 | inode_bh, OCFS2_JOURNAL_ACCESS_CREATE); |
2257 | if (ret < 0) { | 2857 | if (ret < 0) { |
2258 | mlog_errno(ret); | 2858 | mlog_errno(ret); |
2259 | goto end; | 2859 | goto end; |
2260 | } | 2860 | } |
2261 | 2861 | ||
2262 | ret = ocfs2_claim_metadata(osb, handle, meta_ac, 1, | 2862 | ret = ocfs2_claim_metadata(osb, ctxt->handle, ctxt->meta_ac, 1, |
2263 | &suballoc_bit_start, &num_got, | 2863 | &suballoc_bit_start, &num_got, |
2264 | &first_blkno); | 2864 | &first_blkno); |
2265 | if (ret < 0) { | 2865 | if (ret < 0) { |
@@ -2270,7 +2870,7 @@ static int ocfs2_create_xattr_block(handle_t *handle, | |||
2270 | new_bh = sb_getblk(inode->i_sb, first_blkno); | 2870 | new_bh = sb_getblk(inode->i_sb, first_blkno); |
2271 | ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), new_bh); | 2871 | ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), new_bh); |
2272 | 2872 | ||
2273 | ret = ocfs2_journal_access_xb(handle, INODE_CACHE(inode), | 2873 | ret = ocfs2_journal_access_xb(ctxt->handle, INODE_CACHE(inode), |
2274 | new_bh, | 2874 | new_bh, |
2275 | OCFS2_JOURNAL_ACCESS_CREATE); | 2875 | OCFS2_JOURNAL_ACCESS_CREATE); |
2276 | if (ret < 0) { | 2876 | if (ret < 0) { |
@@ -2282,11 +2882,10 @@ static int ocfs2_create_xattr_block(handle_t *handle, | |||
2282 | xblk = (struct ocfs2_xattr_block *)new_bh->b_data; | 2882 | xblk = (struct ocfs2_xattr_block *)new_bh->b_data; |
2283 | memset(xblk, 0, inode->i_sb->s_blocksize); | 2883 | memset(xblk, 0, inode->i_sb->s_blocksize); |
2284 | strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE); | 2884 | strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE); |
2285 | xblk->xb_suballoc_slot = cpu_to_le16(osb->slot_num); | 2885 | xblk->xb_suballoc_slot = cpu_to_le16(ctxt->meta_ac->ac_alloc_slot); |
2286 | xblk->xb_suballoc_bit = cpu_to_le16(suballoc_bit_start); | 2886 | xblk->xb_suballoc_bit = cpu_to_le16(suballoc_bit_start); |
2287 | xblk->xb_fs_generation = cpu_to_le32(osb->fs_generation); | 2887 | xblk->xb_fs_generation = cpu_to_le32(osb->fs_generation); |
2288 | xblk->xb_blkno = cpu_to_le64(first_blkno); | 2888 | xblk->xb_blkno = cpu_to_le64(first_blkno); |
2289 | |||
2290 | if (indexed) { | 2889 | if (indexed) { |
2291 | struct ocfs2_xattr_tree_root *xr = &xblk->xb_attrs.xb_root; | 2890 | struct ocfs2_xattr_tree_root *xr = &xblk->xb_attrs.xb_root; |
2292 | xr->xt_clusters = cpu_to_le32(1); | 2891 | xr->xt_clusters = cpu_to_le32(1); |
@@ -2297,14 +2896,17 @@ static int ocfs2_create_xattr_block(handle_t *handle, | |||
2297 | xr->xt_list.l_next_free_rec = cpu_to_le16(1); | 2896 | xr->xt_list.l_next_free_rec = cpu_to_le16(1); |
2298 | xblk->xb_flags = cpu_to_le16(OCFS2_XATTR_INDEXED); | 2897 | xblk->xb_flags = cpu_to_le16(OCFS2_XATTR_INDEXED); |
2299 | } | 2898 | } |
2899 | ocfs2_journal_dirty(ctxt->handle, new_bh); | ||
2300 | 2900 | ||
2301 | ret = ocfs2_journal_dirty(handle, new_bh); | 2901 | /* Add it to the inode */ |
2302 | if (ret < 0) { | ||
2303 | mlog_errno(ret); | ||
2304 | goto end; | ||
2305 | } | ||
2306 | di->i_xattr_loc = cpu_to_le64(first_blkno); | 2902 | di->i_xattr_loc = cpu_to_le64(first_blkno); |
2307 | ocfs2_journal_dirty(handle, inode_bh); | 2903 | |
2904 | spin_lock(&OCFS2_I(inode)->ip_lock); | ||
2905 | OCFS2_I(inode)->ip_dyn_features |= OCFS2_HAS_XATTR_FL; | ||
2906 | di->i_dyn_features = cpu_to_le16(OCFS2_I(inode)->ip_dyn_features); | ||
2907 | spin_unlock(&OCFS2_I(inode)->ip_lock); | ||
2908 | |||
2909 | ocfs2_journal_dirty(ctxt->handle, inode_bh); | ||
2308 | 2910 | ||
2309 | *ret_bh = new_bh; | 2911 | *ret_bh = new_bh; |
2310 | new_bh = NULL; | 2912 | new_bh = NULL; |
@@ -2326,13 +2928,13 @@ static int ocfs2_xattr_block_set(struct inode *inode, | |||
2326 | struct ocfs2_xattr_set_ctxt *ctxt) | 2928 | struct ocfs2_xattr_set_ctxt *ctxt) |
2327 | { | 2929 | { |
2328 | struct buffer_head *new_bh = NULL; | 2930 | struct buffer_head *new_bh = NULL; |
2329 | handle_t *handle = ctxt->handle; | ||
2330 | struct ocfs2_xattr_block *xblk = NULL; | 2931 | struct ocfs2_xattr_block *xblk = NULL; |
2331 | int ret; | 2932 | int ret; |
2933 | struct ocfs2_xa_loc loc; | ||
2332 | 2934 | ||
2333 | if (!xs->xattr_bh) { | 2935 | if (!xs->xattr_bh) { |
2334 | ret = ocfs2_create_xattr_block(handle, inode, xs->inode_bh, | 2936 | ret = ocfs2_create_xattr_block(inode, xs->inode_bh, ctxt, |
2335 | ctxt->meta_ac, &new_bh, 0); | 2937 | 0, &new_bh); |
2336 | if (ret) { | 2938 | if (ret) { |
2337 | mlog_errno(ret); | 2939 | mlog_errno(ret); |
2338 | goto end; | 2940 | goto end; |
@@ -2348,21 +2950,25 @@ static int ocfs2_xattr_block_set(struct inode *inode, | |||
2348 | xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data; | 2950 | xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data; |
2349 | 2951 | ||
2350 | if (!(le16_to_cpu(xblk->xb_flags) & OCFS2_XATTR_INDEXED)) { | 2952 | if (!(le16_to_cpu(xblk->xb_flags) & OCFS2_XATTR_INDEXED)) { |
2351 | /* Set extended attribute into external block */ | 2953 | ocfs2_init_xattr_block_xa_loc(&loc, inode, xs->xattr_bh, |
2352 | ret = ocfs2_xattr_set_entry(inode, xi, xs, ctxt, | 2954 | xs->not_found ? NULL : xs->here); |
2353 | OCFS2_HAS_XATTR_FL); | ||
2354 | if (!ret || ret != -ENOSPC) | ||
2355 | goto end; | ||
2356 | 2955 | ||
2357 | ret = ocfs2_xattr_create_index_block(inode, xs, ctxt); | 2956 | ret = ocfs2_xa_set(&loc, xi, ctxt); |
2358 | if (ret) | 2957 | if (!ret) |
2958 | xs->here = loc.xl_entry; | ||
2959 | else if (ret != -ENOSPC) | ||
2359 | goto end; | 2960 | goto end; |
2961 | else { | ||
2962 | ret = ocfs2_xattr_create_index_block(inode, xs, ctxt); | ||
2963 | if (ret) | ||
2964 | goto end; | ||
2965 | } | ||
2360 | } | 2966 | } |
2361 | 2967 | ||
2362 | ret = ocfs2_xattr_set_entry_index_block(inode, xi, xs, ctxt); | 2968 | if (le16_to_cpu(xblk->xb_flags) & OCFS2_XATTR_INDEXED) |
2969 | ret = ocfs2_xattr_set_entry_index_block(inode, xi, xs, ctxt); | ||
2363 | 2970 | ||
2364 | end: | 2971 | end: |
2365 | |||
2366 | return ret; | 2972 | return ret; |
2367 | } | 2973 | } |
2368 | 2974 | ||
@@ -2371,7 +2977,6 @@ static int ocfs2_xattr_can_be_in_inode(struct inode *inode, | |||
2371 | struct ocfs2_xattr_info *xi, | 2977 | struct ocfs2_xattr_info *xi, |
2372 | struct ocfs2_xattr_search *xs) | 2978 | struct ocfs2_xattr_search *xs) |
2373 | { | 2979 | { |
2374 | u64 value_size; | ||
2375 | struct ocfs2_xattr_entry *last; | 2980 | struct ocfs2_xattr_entry *last; |
2376 | int free, i; | 2981 | int free, i; |
2377 | size_t min_offs = xs->end - xs->base; | 2982 | size_t min_offs = xs->end - xs->base; |
@@ -2394,13 +2999,7 @@ static int ocfs2_xattr_can_be_in_inode(struct inode *inode, | |||
2394 | 2999 | ||
2395 | BUG_ON(!xs->not_found); | 3000 | BUG_ON(!xs->not_found); |
2396 | 3001 | ||
2397 | if (xi->value_len > OCFS2_XATTR_INLINE_SIZE) | 3002 | if (free >= (sizeof(struct ocfs2_xattr_entry) + namevalue_size_xi(xi))) |
2398 | value_size = OCFS2_XATTR_ROOT_SIZE; | ||
2399 | else | ||
2400 | value_size = OCFS2_XATTR_SIZE(xi->value_len); | ||
2401 | |||
2402 | if (free >= sizeof(struct ocfs2_xattr_entry) + | ||
2403 | OCFS2_XATTR_SIZE(strlen(xi->name)) + value_size) | ||
2404 | return 1; | 3003 | return 1; |
2405 | 3004 | ||
2406 | return 0; | 3005 | return 0; |
@@ -2424,7 +3023,7 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode, | |||
2424 | char *base = NULL; | 3023 | char *base = NULL; |
2425 | int name_offset, name_len = 0; | 3024 | int name_offset, name_len = 0; |
2426 | u32 new_clusters = ocfs2_clusters_for_bytes(inode->i_sb, | 3025 | u32 new_clusters = ocfs2_clusters_for_bytes(inode->i_sb, |
2427 | xi->value_len); | 3026 | xi->xi_value_len); |
2428 | u64 value_size; | 3027 | u64 value_size; |
2429 | 3028 | ||
2430 | /* | 3029 | /* |
@@ -2432,14 +3031,14 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode, | |||
2432 | * No matter whether we replace an old one or add a new one, | 3031 | * No matter whether we replace an old one or add a new one, |
2433 | * we need this for writing. | 3032 | * we need this for writing. |
2434 | */ | 3033 | */ |
2435 | if (xi->value_len > OCFS2_XATTR_INLINE_SIZE) | 3034 | if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) |
2436 | credits += new_clusters * | 3035 | credits += new_clusters * |
2437 | ocfs2_clusters_to_blocks(inode->i_sb, 1); | 3036 | ocfs2_clusters_to_blocks(inode->i_sb, 1); |
2438 | 3037 | ||
2439 | if (xis->not_found && xbs->not_found) { | 3038 | if (xis->not_found && xbs->not_found) { |
2440 | credits += ocfs2_blocks_per_xattr_bucket(inode->i_sb); | 3039 | credits += ocfs2_blocks_per_xattr_bucket(inode->i_sb); |
2441 | 3040 | ||
2442 | if (xi->value_len > OCFS2_XATTR_INLINE_SIZE) { | 3041 | if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) { |
2443 | clusters_add += new_clusters; | 3042 | clusters_add += new_clusters; |
2444 | credits += ocfs2_calc_extend_credits(inode->i_sb, | 3043 | credits += ocfs2_calc_extend_credits(inode->i_sb, |
2445 | &def_xv.xv.xr_list, | 3044 | &def_xv.xv.xr_list, |
@@ -2484,7 +3083,7 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode, | |||
2484 | * The credits for removing the value tree will be extended | 3083 | * The credits for removing the value tree will be extended |
2485 | * by ocfs2_remove_extent itself. | 3084 | * by ocfs2_remove_extent itself. |
2486 | */ | 3085 | */ |
2487 | if (!xi->value) { | 3086 | if (!xi->xi_value) { |
2488 | if (!ocfs2_xattr_is_local(xe)) | 3087 | if (!ocfs2_xattr_is_local(xe)) |
2489 | credits += ocfs2_remove_extent_credits(inode->i_sb); | 3088 | credits += ocfs2_remove_extent_credits(inode->i_sb); |
2490 | 3089 | ||
@@ -2514,7 +3113,7 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode, | |||
2514 | } | 3113 | } |
2515 | } | 3114 | } |
2516 | 3115 | ||
2517 | if (xi->value_len > OCFS2_XATTR_INLINE_SIZE) { | 3116 | if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) { |
2518 | /* the new values will be stored outside. */ | 3117 | /* the new values will be stored outside. */ |
2519 | u32 old_clusters = 0; | 3118 | u32 old_clusters = 0; |
2520 | 3119 | ||
@@ -2547,9 +3146,10 @@ static int ocfs2_calc_xattr_set_need(struct inode *inode, | |||
2547 | * value, we don't need any allocation, otherwise we have | 3146 | * value, we don't need any allocation, otherwise we have |
2548 | * to guess metadata allocation. | 3147 | * to guess metadata allocation. |
2549 | */ | 3148 | */ |
2550 | if ((ocfs2_xattr_is_local(xe) && value_size >= xi->value_len) || | 3149 | if ((ocfs2_xattr_is_local(xe) && |
3150 | (value_size >= xi->xi_value_len)) || | ||
2551 | (!ocfs2_xattr_is_local(xe) && | 3151 | (!ocfs2_xattr_is_local(xe) && |
2552 | OCFS2_XATTR_ROOT_SIZE >= xi->value_len)) | 3152 | OCFS2_XATTR_ROOT_SIZE >= xi->xi_value_len)) |
2553 | goto out; | 3153 | goto out; |
2554 | } | 3154 | } |
2555 | 3155 | ||
@@ -2639,7 +3239,7 @@ static int ocfs2_init_xattr_set_ctxt(struct inode *inode, | |||
2639 | 3239 | ||
2640 | meta_add += extra_meta; | 3240 | meta_add += extra_meta; |
2641 | mlog(0, "Set xattr %s, reserve meta blocks = %d, clusters = %d, " | 3241 | mlog(0, "Set xattr %s, reserve meta blocks = %d, clusters = %d, " |
2642 | "credits = %d\n", xi->name, meta_add, clusters_add, *credits); | 3242 | "credits = %d\n", xi->xi_name, meta_add, clusters_add, *credits); |
2643 | 3243 | ||
2644 | if (meta_add) { | 3244 | if (meta_add) { |
2645 | ret = ocfs2_reserve_new_metadata_blocks(osb, meta_add, | 3245 | ret = ocfs2_reserve_new_metadata_blocks(osb, meta_add, |
@@ -2679,7 +3279,7 @@ static int __ocfs2_xattr_set_handle(struct inode *inode, | |||
2679 | { | 3279 | { |
2680 | int ret = 0, credits, old_found; | 3280 | int ret = 0, credits, old_found; |
2681 | 3281 | ||
2682 | if (!xi->value) { | 3282 | if (!xi->xi_value) { |
2683 | /* Remove existing extended attribute */ | 3283 | /* Remove existing extended attribute */ |
2684 | if (!xis->not_found) | 3284 | if (!xis->not_found) |
2685 | ret = ocfs2_xattr_ibody_set(inode, xi, xis, ctxt); | 3285 | ret = ocfs2_xattr_ibody_set(inode, xi, xis, ctxt); |
@@ -2693,8 +3293,8 @@ static int __ocfs2_xattr_set_handle(struct inode *inode, | |||
2693 | * If succeed and that extended attribute existing in | 3293 | * If succeed and that extended attribute existing in |
2694 | * external block, then we will remove it. | 3294 | * external block, then we will remove it. |
2695 | */ | 3295 | */ |
2696 | xi->value = NULL; | 3296 | xi->xi_value = NULL; |
2697 | xi->value_len = 0; | 3297 | xi->xi_value_len = 0; |
2698 | 3298 | ||
2699 | old_found = xis->not_found; | 3299 | old_found = xis->not_found; |
2700 | xis->not_found = -ENODATA; | 3300 | xis->not_found = -ENODATA; |
@@ -2722,8 +3322,8 @@ static int __ocfs2_xattr_set_handle(struct inode *inode, | |||
2722 | } else if (ret == -ENOSPC) { | 3322 | } else if (ret == -ENOSPC) { |
2723 | if (di->i_xattr_loc && !xbs->xattr_bh) { | 3323 | if (di->i_xattr_loc && !xbs->xattr_bh) { |
2724 | ret = ocfs2_xattr_block_find(inode, | 3324 | ret = ocfs2_xattr_block_find(inode, |
2725 | xi->name_index, | 3325 | xi->xi_name_index, |
2726 | xi->name, xbs); | 3326 | xi->xi_name, xbs); |
2727 | if (ret) | 3327 | if (ret) |
2728 | goto out; | 3328 | goto out; |
2729 | 3329 | ||
@@ -2762,8 +3362,8 @@ static int __ocfs2_xattr_set_handle(struct inode *inode, | |||
2762 | * If succeed and that extended attribute | 3362 | * If succeed and that extended attribute |
2763 | * existing in inode, we will remove it. | 3363 | * existing in inode, we will remove it. |
2764 | */ | 3364 | */ |
2765 | xi->value = NULL; | 3365 | xi->xi_value = NULL; |
2766 | xi->value_len = 0; | 3366 | xi->xi_value_len = 0; |
2767 | xbs->not_found = -ENODATA; | 3367 | xbs->not_found = -ENODATA; |
2768 | ret = ocfs2_calc_xattr_set_need(inode, | 3368 | ret = ocfs2_calc_xattr_set_need(inode, |
2769 | di, | 3369 | di, |
@@ -2829,10 +3429,11 @@ int ocfs2_xattr_set_handle(handle_t *handle, | |||
2829 | int ret; | 3429 | int ret; |
2830 | 3430 | ||
2831 | struct ocfs2_xattr_info xi = { | 3431 | struct ocfs2_xattr_info xi = { |
2832 | .name_index = name_index, | 3432 | .xi_name_index = name_index, |
2833 | .name = name, | 3433 | .xi_name = name, |
2834 | .value = value, | 3434 | .xi_name_len = strlen(name), |
2835 | .value_len = value_len, | 3435 | .xi_value = value, |
3436 | .xi_value_len = value_len, | ||
2836 | }; | 3437 | }; |
2837 | 3438 | ||
2838 | struct ocfs2_xattr_search xis = { | 3439 | struct ocfs2_xattr_search xis = { |
@@ -2912,10 +3513,11 @@ int ocfs2_xattr_set(struct inode *inode, | |||
2912 | struct ocfs2_refcount_tree *ref_tree = NULL; | 3513 | struct ocfs2_refcount_tree *ref_tree = NULL; |
2913 | 3514 | ||
2914 | struct ocfs2_xattr_info xi = { | 3515 | struct ocfs2_xattr_info xi = { |
2915 | .name_index = name_index, | 3516 | .xi_name_index = name_index, |
2916 | .name = name, | 3517 | .xi_name = name, |
2917 | .value = value, | 3518 | .xi_name_len = strlen(name), |
2918 | .value_len = value_len, | 3519 | .xi_value = value, |
3520 | .xi_value_len = value_len, | ||
2919 | }; | 3521 | }; |
2920 | 3522 | ||
2921 | struct ocfs2_xattr_search xis = { | 3523 | struct ocfs2_xattr_search xis = { |
@@ -3759,7 +4361,7 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode, | |||
3759 | struct ocfs2_xattr_bucket *bucket) | 4361 | struct ocfs2_xattr_bucket *bucket) |
3760 | { | 4362 | { |
3761 | int ret, i; | 4363 | int ret, i; |
3762 | size_t end, offset, len, value_len; | 4364 | size_t end, offset, len; |
3763 | struct ocfs2_xattr_header *xh; | 4365 | struct ocfs2_xattr_header *xh; |
3764 | char *entries, *buf, *bucket_buf = NULL; | 4366 | char *entries, *buf, *bucket_buf = NULL; |
3765 | u64 blkno = bucket_blkno(bucket); | 4367 | u64 blkno = bucket_blkno(bucket); |
@@ -3813,12 +4415,7 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode, | |||
3813 | end = OCFS2_XATTR_BUCKET_SIZE; | 4415 | end = OCFS2_XATTR_BUCKET_SIZE; |
3814 | for (i = 0; i < le16_to_cpu(xh->xh_count); i++, xe++) { | 4416 | for (i = 0; i < le16_to_cpu(xh->xh_count); i++, xe++) { |
3815 | offset = le16_to_cpu(xe->xe_name_offset); | 4417 | offset = le16_to_cpu(xe->xe_name_offset); |
3816 | if (ocfs2_xattr_is_local(xe)) | 4418 | len = namevalue_size_xe(xe); |
3817 | value_len = OCFS2_XATTR_SIZE( | ||
3818 | le64_to_cpu(xe->xe_value_size)); | ||
3819 | else | ||
3820 | value_len = OCFS2_XATTR_ROOT_SIZE; | ||
3821 | len = OCFS2_XATTR_SIZE(xe->xe_name_len) + value_len; | ||
3822 | 4419 | ||
3823 | /* | 4420 | /* |
3824 | * We must make sure that the name/value pair | 4421 | * We must make sure that the name/value pair |
@@ -4007,7 +4604,7 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, | |||
4007 | int new_bucket_head) | 4604 | int new_bucket_head) |
4008 | { | 4605 | { |
4009 | int ret, i; | 4606 | int ret, i; |
4010 | int count, start, len, name_value_len = 0, xe_len, name_offset = 0; | 4607 | int count, start, len, name_value_len = 0, name_offset = 0; |
4011 | struct ocfs2_xattr_bucket *s_bucket = NULL, *t_bucket = NULL; | 4608 | struct ocfs2_xattr_bucket *s_bucket = NULL, *t_bucket = NULL; |
4012 | struct ocfs2_xattr_header *xh; | 4609 | struct ocfs2_xattr_header *xh; |
4013 | struct ocfs2_xattr_entry *xe; | 4610 | struct ocfs2_xattr_entry *xe; |
@@ -4098,13 +4695,7 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, | |||
4098 | name_value_len = 0; | 4695 | name_value_len = 0; |
4099 | for (i = 0; i < start; i++) { | 4696 | for (i = 0; i < start; i++) { |
4100 | xe = &xh->xh_entries[i]; | 4697 | xe = &xh->xh_entries[i]; |
4101 | xe_len = OCFS2_XATTR_SIZE(xe->xe_name_len); | 4698 | name_value_len += namevalue_size_xe(xe); |
4102 | if (ocfs2_xattr_is_local(xe)) | ||
4103 | xe_len += | ||
4104 | OCFS2_XATTR_SIZE(le64_to_cpu(xe->xe_value_size)); | ||
4105 | else | ||
4106 | xe_len += OCFS2_XATTR_ROOT_SIZE; | ||
4107 | name_value_len += xe_len; | ||
4108 | if (le16_to_cpu(xe->xe_name_offset) < name_offset) | 4699 | if (le16_to_cpu(xe->xe_name_offset) < name_offset) |
4109 | name_offset = le16_to_cpu(xe->xe_name_offset); | 4700 | name_offset = le16_to_cpu(xe->xe_name_offset); |
4110 | } | 4701 | } |
@@ -4134,12 +4725,6 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, | |||
4134 | xh->xh_free_start = cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE); | 4725 | xh->xh_free_start = cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE); |
4135 | for (i = 0; i < le16_to_cpu(xh->xh_count); i++) { | 4726 | for (i = 0; i < le16_to_cpu(xh->xh_count); i++) { |
4136 | xe = &xh->xh_entries[i]; | 4727 | xe = &xh->xh_entries[i]; |
4137 | xe_len = OCFS2_XATTR_SIZE(xe->xe_name_len); | ||
4138 | if (ocfs2_xattr_is_local(xe)) | ||
4139 | xe_len += | ||
4140 | OCFS2_XATTR_SIZE(le64_to_cpu(xe->xe_value_size)); | ||
4141 | else | ||
4142 | xe_len += OCFS2_XATTR_ROOT_SIZE; | ||
4143 | if (le16_to_cpu(xe->xe_name_offset) < | 4728 | if (le16_to_cpu(xe->xe_name_offset) < |
4144 | le16_to_cpu(xh->xh_free_start)) | 4729 | le16_to_cpu(xh->xh_free_start)) |
4145 | xh->xh_free_start = xe->xe_name_offset; | 4730 | xh->xh_free_start = xe->xe_name_offset; |
@@ -4751,195 +5336,6 @@ static inline char *ocfs2_xattr_bucket_get_val(struct inode *inode, | |||
4751 | } | 5336 | } |
4752 | 5337 | ||
4753 | /* | 5338 | /* |
4754 | * Handle the normal xattr set, including replace, delete and new. | ||
4755 | * | ||
4756 | * Note: "local" indicates the real data's locality. So we can't | ||
4757 | * just its bucket locality by its length. | ||
4758 | */ | ||
4759 | static void ocfs2_xattr_set_entry_normal(struct inode *inode, | ||
4760 | struct ocfs2_xattr_info *xi, | ||
4761 | struct ocfs2_xattr_search *xs, | ||
4762 | u32 name_hash, | ||
4763 | int local) | ||
4764 | { | ||
4765 | struct ocfs2_xattr_entry *last, *xe; | ||
4766 | int name_len = strlen(xi->name); | ||
4767 | struct ocfs2_xattr_header *xh = xs->header; | ||
4768 | u16 count = le16_to_cpu(xh->xh_count), start; | ||
4769 | size_t blocksize = inode->i_sb->s_blocksize; | ||
4770 | char *val; | ||
4771 | size_t offs, size, new_size; | ||
4772 | |||
4773 | last = &xh->xh_entries[count]; | ||
4774 | if (!xs->not_found) { | ||
4775 | xe = xs->here; | ||
4776 | offs = le16_to_cpu(xe->xe_name_offset); | ||
4777 | if (ocfs2_xattr_is_local(xe)) | ||
4778 | size = OCFS2_XATTR_SIZE(name_len) + | ||
4779 | OCFS2_XATTR_SIZE(le64_to_cpu(xe->xe_value_size)); | ||
4780 | else | ||
4781 | size = OCFS2_XATTR_SIZE(name_len) + | ||
4782 | OCFS2_XATTR_SIZE(OCFS2_XATTR_ROOT_SIZE); | ||
4783 | |||
4784 | /* | ||
4785 | * If the new value will be stored outside, xi->value has been | ||
4786 | * initalized as an empty ocfs2_xattr_value_root, and the same | ||
4787 | * goes with xi->value_len, so we can set new_size safely here. | ||
4788 | * See ocfs2_xattr_set_in_bucket. | ||
4789 | */ | ||
4790 | new_size = OCFS2_XATTR_SIZE(name_len) + | ||
4791 | OCFS2_XATTR_SIZE(xi->value_len); | ||
4792 | |||
4793 | le16_add_cpu(&xh->xh_name_value_len, -size); | ||
4794 | if (xi->value) { | ||
4795 | if (new_size > size) | ||
4796 | goto set_new_name_value; | ||
4797 | |||
4798 | /* Now replace the old value with new one. */ | ||
4799 | if (local) | ||
4800 | xe->xe_value_size = cpu_to_le64(xi->value_len); | ||
4801 | else | ||
4802 | xe->xe_value_size = 0; | ||
4803 | |||
4804 | val = ocfs2_xattr_bucket_get_val(inode, | ||
4805 | xs->bucket, offs); | ||
4806 | memset(val + OCFS2_XATTR_SIZE(name_len), 0, | ||
4807 | size - OCFS2_XATTR_SIZE(name_len)); | ||
4808 | if (OCFS2_XATTR_SIZE(xi->value_len) > 0) | ||
4809 | memcpy(val + OCFS2_XATTR_SIZE(name_len), | ||
4810 | xi->value, xi->value_len); | ||
4811 | |||
4812 | le16_add_cpu(&xh->xh_name_value_len, new_size); | ||
4813 | ocfs2_xattr_set_local(xe, local); | ||
4814 | return; | ||
4815 | } else { | ||
4816 | /* | ||
4817 | * Remove the old entry if there is more than one. | ||
4818 | * We don't remove the last entry so that we can | ||
4819 | * use it to indicate the hash value of the empty | ||
4820 | * bucket. | ||
4821 | */ | ||
4822 | last -= 1; | ||
4823 | le16_add_cpu(&xh->xh_count, -1); | ||
4824 | if (xh->xh_count) { | ||
4825 | memmove(xe, xe + 1, | ||
4826 | (void *)last - (void *)xe); | ||
4827 | memset(last, 0, | ||
4828 | sizeof(struct ocfs2_xattr_entry)); | ||
4829 | } else | ||
4830 | xh->xh_free_start = | ||
4831 | cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE); | ||
4832 | |||
4833 | return; | ||
4834 | } | ||
4835 | } else { | ||
4836 | /* find a new entry for insert. */ | ||
4837 | int low = 0, high = count - 1, tmp; | ||
4838 | struct ocfs2_xattr_entry *tmp_xe; | ||
4839 | |||
4840 | while (low <= high && count) { | ||
4841 | tmp = (low + high) / 2; | ||
4842 | tmp_xe = &xh->xh_entries[tmp]; | ||
4843 | |||
4844 | if (name_hash > le32_to_cpu(tmp_xe->xe_name_hash)) | ||
4845 | low = tmp + 1; | ||
4846 | else if (name_hash < | ||
4847 | le32_to_cpu(tmp_xe->xe_name_hash)) | ||
4848 | high = tmp - 1; | ||
4849 | else { | ||
4850 | low = tmp; | ||
4851 | break; | ||
4852 | } | ||
4853 | } | ||
4854 | |||
4855 | xe = &xh->xh_entries[low]; | ||
4856 | if (low != count) | ||
4857 | memmove(xe + 1, xe, (void *)last - (void *)xe); | ||
4858 | |||
4859 | le16_add_cpu(&xh->xh_count, 1); | ||
4860 | memset(xe, 0, sizeof(struct ocfs2_xattr_entry)); | ||
4861 | xe->xe_name_hash = cpu_to_le32(name_hash); | ||
4862 | xe->xe_name_len = name_len; | ||
4863 | ocfs2_xattr_set_type(xe, xi->name_index); | ||
4864 | } | ||
4865 | |||
4866 | set_new_name_value: | ||
4867 | /* Insert the new name+value. */ | ||
4868 | size = OCFS2_XATTR_SIZE(name_len) + OCFS2_XATTR_SIZE(xi->value_len); | ||
4869 | |||
4870 | /* | ||
4871 | * We must make sure that the name/value pair | ||
4872 | * exists in the same block. | ||
4873 | */ | ||
4874 | offs = le16_to_cpu(xh->xh_free_start); | ||
4875 | start = offs - size; | ||
4876 | |||
4877 | if (start >> inode->i_sb->s_blocksize_bits != | ||
4878 | (offs - 1) >> inode->i_sb->s_blocksize_bits) { | ||
4879 | offs = offs - offs % blocksize; | ||
4880 | xh->xh_free_start = cpu_to_le16(offs); | ||
4881 | } | ||
4882 | |||
4883 | val = ocfs2_xattr_bucket_get_val(inode, xs->bucket, offs - size); | ||
4884 | xe->xe_name_offset = cpu_to_le16(offs - size); | ||
4885 | |||
4886 | memset(val, 0, size); | ||
4887 | memcpy(val, xi->name, name_len); | ||
4888 | memcpy(val + OCFS2_XATTR_SIZE(name_len), xi->value, xi->value_len); | ||
4889 | |||
4890 | xe->xe_value_size = cpu_to_le64(xi->value_len); | ||
4891 | ocfs2_xattr_set_local(xe, local); | ||
4892 | xs->here = xe; | ||
4893 | le16_add_cpu(&xh->xh_free_start, -size); | ||
4894 | le16_add_cpu(&xh->xh_name_value_len, size); | ||
4895 | |||
4896 | return; | ||
4897 | } | ||
4898 | |||
4899 | /* | ||
4900 | * Set the xattr entry in the specified bucket. | ||
4901 | * The bucket is indicated by xs->bucket and it should have the enough | ||
4902 | * space for the xattr insertion. | ||
4903 | */ | ||
4904 | static int ocfs2_xattr_set_entry_in_bucket(struct inode *inode, | ||
4905 | handle_t *handle, | ||
4906 | struct ocfs2_xattr_info *xi, | ||
4907 | struct ocfs2_xattr_search *xs, | ||
4908 | u32 name_hash, | ||
4909 | int local) | ||
4910 | { | ||
4911 | int ret; | ||
4912 | u64 blkno; | ||
4913 | |||
4914 | mlog(0, "Set xattr entry len = %lu index = %d in bucket %llu\n", | ||
4915 | (unsigned long)xi->value_len, xi->name_index, | ||
4916 | (unsigned long long)bucket_blkno(xs->bucket)); | ||
4917 | |||
4918 | if (!xs->bucket->bu_bhs[1]) { | ||
4919 | blkno = bucket_blkno(xs->bucket); | ||
4920 | ocfs2_xattr_bucket_relse(xs->bucket); | ||
4921 | ret = ocfs2_read_xattr_bucket(xs->bucket, blkno); | ||
4922 | if (ret) { | ||
4923 | mlog_errno(ret); | ||
4924 | goto out; | ||
4925 | } | ||
4926 | } | ||
4927 | |||
4928 | ret = ocfs2_xattr_bucket_journal_access(handle, xs->bucket, | ||
4929 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
4930 | if (ret < 0) { | ||
4931 | mlog_errno(ret); | ||
4932 | goto out; | ||
4933 | } | ||
4934 | |||
4935 | ocfs2_xattr_set_entry_normal(inode, xi, xs, name_hash, local); | ||
4936 | ocfs2_xattr_bucket_journal_dirty(handle, xs->bucket); | ||
4937 | |||
4938 | out: | ||
4939 | return ret; | ||
4940 | } | ||
4941 | |||
4942 | /* | ||
4943 | * Truncate the specified xe_off entry in xattr bucket. | 5339 | * Truncate the specified xe_off entry in xattr bucket. |
4944 | * bucket is indicated by header_bh and len is the new length. | 5340 | * bucket is indicated by header_bh and len is the new length. |
4945 | * Both the ocfs2_xattr_value_root and the entry will be updated here. | 5341 | * Both the ocfs2_xattr_value_root and the entry will be updated here. |
@@ -5009,66 +5405,6 @@ out: | |||
5009 | return ret; | 5405 | return ret; |
5010 | } | 5406 | } |
5011 | 5407 | ||
5012 | static int ocfs2_xattr_bucket_value_truncate_xs(struct inode *inode, | ||
5013 | struct ocfs2_xattr_search *xs, | ||
5014 | int len, | ||
5015 | struct ocfs2_xattr_set_ctxt *ctxt) | ||
5016 | { | ||
5017 | int ret, offset; | ||
5018 | struct ocfs2_xattr_entry *xe = xs->here; | ||
5019 | struct ocfs2_xattr_header *xh = (struct ocfs2_xattr_header *)xs->base; | ||
5020 | |||
5021 | BUG_ON(!xs->bucket->bu_bhs[0] || !xe || ocfs2_xattr_is_local(xe)); | ||
5022 | |||
5023 | offset = xe - xh->xh_entries; | ||
5024 | ret = ocfs2_xattr_bucket_value_truncate(inode, xs->bucket, | ||
5025 | offset, len, ctxt); | ||
5026 | if (ret) | ||
5027 | mlog_errno(ret); | ||
5028 | |||
5029 | return ret; | ||
5030 | } | ||
5031 | |||
5032 | static int ocfs2_xattr_bucket_set_value_outside(struct inode *inode, | ||
5033 | handle_t *handle, | ||
5034 | struct ocfs2_xattr_search *xs, | ||
5035 | char *val, | ||
5036 | int value_len) | ||
5037 | { | ||
5038 | int ret, offset, block_off; | ||
5039 | struct ocfs2_xattr_value_root *xv; | ||
5040 | struct ocfs2_xattr_entry *xe = xs->here; | ||
5041 | struct ocfs2_xattr_header *xh = bucket_xh(xs->bucket); | ||
5042 | void *base; | ||
5043 | struct ocfs2_xattr_value_buf vb = { | ||
5044 | .vb_access = ocfs2_journal_access, | ||
5045 | }; | ||
5046 | |||
5047 | BUG_ON(!xs->base || !xe || ocfs2_xattr_is_local(xe)); | ||
5048 | |||
5049 | ret = ocfs2_xattr_bucket_get_name_value(inode->i_sb, xh, | ||
5050 | xe - xh->xh_entries, | ||
5051 | &block_off, | ||
5052 | &offset); | ||
5053 | if (ret) { | ||
5054 | mlog_errno(ret); | ||
5055 | goto out; | ||
5056 | } | ||
5057 | |||
5058 | base = bucket_block(xs->bucket, block_off); | ||
5059 | xv = (struct ocfs2_xattr_value_root *)(base + offset + | ||
5060 | OCFS2_XATTR_SIZE(xe->xe_name_len)); | ||
5061 | |||
5062 | vb.vb_xv = xv; | ||
5063 | vb.vb_bh = xs->bucket->bu_bhs[block_off]; | ||
5064 | ret = __ocfs2_xattr_set_value_outside(inode, handle, | ||
5065 | &vb, val, value_len); | ||
5066 | if (ret) | ||
5067 | mlog_errno(ret); | ||
5068 | out: | ||
5069 | return ret; | ||
5070 | } | ||
5071 | |||
5072 | static int ocfs2_rm_xattr_cluster(struct inode *inode, | 5408 | static int ocfs2_rm_xattr_cluster(struct inode *inode, |
5073 | struct buffer_head *root_bh, | 5409 | struct buffer_head *root_bh, |
5074 | u64 blkno, | 5410 | u64 blkno, |
@@ -5167,128 +5503,6 @@ out: | |||
5167 | return ret; | 5503 | return ret; |
5168 | } | 5504 | } |
5169 | 5505 | ||
5170 | static void ocfs2_xattr_bucket_remove_xs(struct inode *inode, | ||
5171 | handle_t *handle, | ||
5172 | struct ocfs2_xattr_search *xs) | ||
5173 | { | ||
5174 | struct ocfs2_xattr_header *xh = bucket_xh(xs->bucket); | ||
5175 | struct ocfs2_xattr_entry *last = &xh->xh_entries[ | ||
5176 | le16_to_cpu(xh->xh_count) - 1]; | ||
5177 | int ret = 0; | ||
5178 | |||
5179 | ret = ocfs2_xattr_bucket_journal_access(handle, xs->bucket, | ||
5180 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
5181 | if (ret) { | ||
5182 | mlog_errno(ret); | ||
5183 | return; | ||
5184 | } | ||
5185 | |||
5186 | /* Remove the old entry. */ | ||
5187 | memmove(xs->here, xs->here + 1, | ||
5188 | (void *)last - (void *)xs->here); | ||
5189 | memset(last, 0, sizeof(struct ocfs2_xattr_entry)); | ||
5190 | le16_add_cpu(&xh->xh_count, -1); | ||
5191 | |||
5192 | ocfs2_xattr_bucket_journal_dirty(handle, xs->bucket); | ||
5193 | } | ||
5194 | |||
5195 | /* | ||
5196 | * Set the xattr name/value in the bucket specified in xs. | ||
5197 | * | ||
5198 | * As the new value in xi may be stored in the bucket or in an outside cluster, | ||
5199 | * we divide the whole process into 3 steps: | ||
5200 | * 1. insert name/value in the bucket(ocfs2_xattr_set_entry_in_bucket) | ||
5201 | * 2. truncate of the outside cluster(ocfs2_xattr_bucket_value_truncate_xs) | ||
5202 | * 3. Set the value to the outside cluster(ocfs2_xattr_bucket_set_value_outside) | ||
5203 | * 4. If the clusters for the new outside value can't be allocated, we need | ||
5204 | * to free the xattr we allocated in set. | ||
5205 | */ | ||
5206 | static int ocfs2_xattr_set_in_bucket(struct inode *inode, | ||
5207 | struct ocfs2_xattr_info *xi, | ||
5208 | struct ocfs2_xattr_search *xs, | ||
5209 | struct ocfs2_xattr_set_ctxt *ctxt) | ||
5210 | { | ||
5211 | int ret, local = 1; | ||
5212 | size_t value_len; | ||
5213 | char *val = (char *)xi->value; | ||
5214 | struct ocfs2_xattr_entry *xe = xs->here; | ||
5215 | u32 name_hash = ocfs2_xattr_name_hash(inode, xi->name, | ||
5216 | strlen(xi->name)); | ||
5217 | |||
5218 | if (!xs->not_found && !ocfs2_xattr_is_local(xe)) { | ||
5219 | /* | ||
5220 | * We need to truncate the xattr storage first. | ||
5221 | * | ||
5222 | * If both the old and new value are stored to | ||
5223 | * outside block, we only need to truncate | ||
5224 | * the storage and then set the value outside. | ||
5225 | * | ||
5226 | * If the new value should be stored within block, | ||
5227 | * we should free all the outside block first and | ||
5228 | * the modification to the xattr block will be done | ||
5229 | * by following steps. | ||
5230 | */ | ||
5231 | if (xi->value_len > OCFS2_XATTR_INLINE_SIZE) | ||
5232 | value_len = xi->value_len; | ||
5233 | else | ||
5234 | value_len = 0; | ||
5235 | |||
5236 | ret = ocfs2_xattr_bucket_value_truncate_xs(inode, xs, | ||
5237 | value_len, | ||
5238 | ctxt); | ||
5239 | if (ret) | ||
5240 | goto out; | ||
5241 | |||
5242 | if (value_len) | ||
5243 | goto set_value_outside; | ||
5244 | } | ||
5245 | |||
5246 | value_len = xi->value_len; | ||
5247 | /* So we have to handle the inside block change now. */ | ||
5248 | if (value_len > OCFS2_XATTR_INLINE_SIZE) { | ||
5249 | /* | ||
5250 | * If the new value will be stored outside of block, | ||
5251 | * initalize a new empty value root and insert it first. | ||
5252 | */ | ||
5253 | local = 0; | ||
5254 | xi->value = &def_xv; | ||
5255 | xi->value_len = OCFS2_XATTR_ROOT_SIZE; | ||
5256 | } | ||
5257 | |||
5258 | ret = ocfs2_xattr_set_entry_in_bucket(inode, ctxt->handle, xi, xs, | ||
5259 | name_hash, local); | ||
5260 | if (ret) { | ||
5261 | mlog_errno(ret); | ||
5262 | goto out; | ||
5263 | } | ||
5264 | |||
5265 | if (value_len <= OCFS2_XATTR_INLINE_SIZE) | ||
5266 | goto out; | ||
5267 | |||
5268 | /* allocate the space now for the outside block storage. */ | ||
5269 | ret = ocfs2_xattr_bucket_value_truncate_xs(inode, xs, | ||
5270 | value_len, ctxt); | ||
5271 | if (ret) { | ||
5272 | mlog_errno(ret); | ||
5273 | |||
5274 | if (xs->not_found) { | ||
5275 | /* | ||
5276 | * We can't allocate enough clusters for outside | ||
5277 | * storage and we have allocated xattr already, | ||
5278 | * so need to remove it. | ||
5279 | */ | ||
5280 | ocfs2_xattr_bucket_remove_xs(inode, ctxt->handle, xs); | ||
5281 | } | ||
5282 | goto out; | ||
5283 | } | ||
5284 | |||
5285 | set_value_outside: | ||
5286 | ret = ocfs2_xattr_bucket_set_value_outside(inode, ctxt->handle, | ||
5287 | xs, val, value_len); | ||
5288 | out: | ||
5289 | return ret; | ||
5290 | } | ||
5291 | |||
5292 | /* | 5506 | /* |
5293 | * check whether the xattr bucket is filled up with the same hash value. | 5507 | * check whether the xattr bucket is filled up with the same hash value. |
5294 | * If we want to insert the xattr with the same hash, return -ENOSPC. | 5508 | * If we want to insert the xattr with the same hash, return -ENOSPC. |
@@ -5317,156 +5531,116 @@ static int ocfs2_check_xattr_bucket_collision(struct inode *inode, | |||
5317 | return 0; | 5531 | return 0; |
5318 | } | 5532 | } |
5319 | 5533 | ||
5320 | static int ocfs2_xattr_set_entry_index_block(struct inode *inode, | 5534 | /* |
5321 | struct ocfs2_xattr_info *xi, | 5535 | * Try to set the entry in the current bucket. If we fail, the caller |
5322 | struct ocfs2_xattr_search *xs, | 5536 | * will handle getting us another bucket. |
5323 | struct ocfs2_xattr_set_ctxt *ctxt) | 5537 | */ |
5538 | static int ocfs2_xattr_set_entry_bucket(struct inode *inode, | ||
5539 | struct ocfs2_xattr_info *xi, | ||
5540 | struct ocfs2_xattr_search *xs, | ||
5541 | struct ocfs2_xattr_set_ctxt *ctxt) | ||
5324 | { | 5542 | { |
5325 | struct ocfs2_xattr_header *xh; | 5543 | int ret; |
5326 | struct ocfs2_xattr_entry *xe; | 5544 | struct ocfs2_xa_loc loc; |
5327 | u16 count, header_size, xh_free_start; | ||
5328 | int free, max_free, need, old; | ||
5329 | size_t value_size = 0, name_len = strlen(xi->name); | ||
5330 | size_t blocksize = inode->i_sb->s_blocksize; | ||
5331 | int ret, allocation = 0; | ||
5332 | |||
5333 | mlog_entry("Set xattr %s in xattr index block\n", xi->name); | ||
5334 | |||
5335 | try_again: | ||
5336 | xh = xs->header; | ||
5337 | count = le16_to_cpu(xh->xh_count); | ||
5338 | xh_free_start = le16_to_cpu(xh->xh_free_start); | ||
5339 | header_size = sizeof(struct ocfs2_xattr_header) + | ||
5340 | count * sizeof(struct ocfs2_xattr_entry); | ||
5341 | max_free = OCFS2_XATTR_BUCKET_SIZE - header_size - | ||
5342 | le16_to_cpu(xh->xh_name_value_len) - OCFS2_XATTR_HEADER_GAP; | ||
5343 | |||
5344 | mlog_bug_on_msg(header_size > blocksize, "bucket %llu has header size " | ||
5345 | "of %u which exceed block size\n", | ||
5346 | (unsigned long long)bucket_blkno(xs->bucket), | ||
5347 | header_size); | ||
5348 | 5545 | ||
5349 | if (xi->value && xi->value_len > OCFS2_XATTR_INLINE_SIZE) | 5546 | mlog_entry("Set xattr %s in xattr bucket\n", xi->xi_name); |
5350 | value_size = OCFS2_XATTR_ROOT_SIZE; | ||
5351 | else if (xi->value) | ||
5352 | value_size = OCFS2_XATTR_SIZE(xi->value_len); | ||
5353 | 5547 | ||
5354 | if (xs->not_found) | 5548 | ocfs2_init_xattr_bucket_xa_loc(&loc, xs->bucket, |
5355 | need = sizeof(struct ocfs2_xattr_entry) + | 5549 | xs->not_found ? NULL : xs->here); |
5356 | OCFS2_XATTR_SIZE(name_len) + value_size; | 5550 | ret = ocfs2_xa_set(&loc, xi, ctxt); |
5357 | else { | 5551 | if (!ret) { |
5358 | need = value_size + OCFS2_XATTR_SIZE(name_len); | 5552 | xs->here = loc.xl_entry; |
5553 | goto out; | ||
5554 | } | ||
5555 | if (ret != -ENOSPC) { | ||
5556 | mlog_errno(ret); | ||
5557 | goto out; | ||
5558 | } | ||
5359 | 5559 | ||
5360 | /* | 5560 | /* Ok, we need space. Let's try defragmenting the bucket. */ |
5361 | * We only replace the old value if the new length is smaller | 5561 | ret = ocfs2_defrag_xattr_bucket(inode, ctxt->handle, |
5362 | * than the old one. Otherwise we will allocate new space in the | 5562 | xs->bucket); |
5363 | * bucket to store it. | 5563 | if (ret) { |
5364 | */ | 5564 | mlog_errno(ret); |
5365 | xe = xs->here; | 5565 | goto out; |
5366 | if (ocfs2_xattr_is_local(xe)) | 5566 | } |
5367 | old = OCFS2_XATTR_SIZE(le64_to_cpu(xe->xe_value_size)); | ||
5368 | else | ||
5369 | old = OCFS2_XATTR_SIZE(OCFS2_XATTR_ROOT_SIZE); | ||
5370 | 5567 | ||
5371 | if (old >= value_size) | 5568 | ret = ocfs2_xa_set(&loc, xi, ctxt); |
5372 | need = 0; | 5569 | if (!ret) { |
5570 | xs->here = loc.xl_entry; | ||
5571 | goto out; | ||
5373 | } | 5572 | } |
5573 | if (ret != -ENOSPC) | ||
5574 | mlog_errno(ret); | ||
5374 | 5575 | ||
5375 | free = xh_free_start - header_size - OCFS2_XATTR_HEADER_GAP; | ||
5376 | /* | ||
5377 | * We need to make sure the new name/value pair | ||
5378 | * can exist in the same block. | ||
5379 | */ | ||
5380 | if (xh_free_start % blocksize < need) | ||
5381 | free -= xh_free_start % blocksize; | ||
5382 | |||
5383 | mlog(0, "xs->not_found = %d, in xattr bucket %llu: free = %d, " | ||
5384 | "need = %d, max_free = %d, xh_free_start = %u, xh_name_value_len =" | ||
5385 | " %u\n", xs->not_found, | ||
5386 | (unsigned long long)bucket_blkno(xs->bucket), | ||
5387 | free, need, max_free, le16_to_cpu(xh->xh_free_start), | ||
5388 | le16_to_cpu(xh->xh_name_value_len)); | ||
5389 | |||
5390 | if (free < need || | ||
5391 | (xs->not_found && | ||
5392 | count == ocfs2_xattr_max_xe_in_bucket(inode->i_sb))) { | ||
5393 | if (need <= max_free && | ||
5394 | count < ocfs2_xattr_max_xe_in_bucket(inode->i_sb)) { | ||
5395 | /* | ||
5396 | * We can create the space by defragment. Since only the | ||
5397 | * name/value will be moved, the xe shouldn't be changed | ||
5398 | * in xs. | ||
5399 | */ | ||
5400 | ret = ocfs2_defrag_xattr_bucket(inode, ctxt->handle, | ||
5401 | xs->bucket); | ||
5402 | if (ret) { | ||
5403 | mlog_errno(ret); | ||
5404 | goto out; | ||
5405 | } | ||
5406 | 5576 | ||
5407 | xh_free_start = le16_to_cpu(xh->xh_free_start); | 5577 | out: |
5408 | free = xh_free_start - header_size | 5578 | mlog_exit(ret); |
5409 | - OCFS2_XATTR_HEADER_GAP; | 5579 | return ret; |
5410 | if (xh_free_start % blocksize < need) | 5580 | } |
5411 | free -= xh_free_start % blocksize; | ||
5412 | 5581 | ||
5413 | if (free >= need) | 5582 | static int ocfs2_xattr_set_entry_index_block(struct inode *inode, |
5414 | goto xattr_set; | 5583 | struct ocfs2_xattr_info *xi, |
5584 | struct ocfs2_xattr_search *xs, | ||
5585 | struct ocfs2_xattr_set_ctxt *ctxt) | ||
5586 | { | ||
5587 | int ret; | ||
5415 | 5588 | ||
5416 | mlog(0, "Can't get enough space for xattr insert by " | 5589 | mlog_entry("Set xattr %s in xattr index block\n", xi->xi_name); |
5417 | "defragment. Need %u bytes, but we have %d, so " | ||
5418 | "allocate new bucket for it.\n", need, free); | ||
5419 | } | ||
5420 | 5590 | ||
5421 | /* | 5591 | ret = ocfs2_xattr_set_entry_bucket(inode, xi, xs, ctxt); |
5422 | * We have to add new buckets or clusters and one | 5592 | if (!ret) |
5423 | * allocation should leave us enough space for insert. | 5593 | goto out; |
5424 | */ | 5594 | if (ret != -ENOSPC) { |
5425 | BUG_ON(allocation); | 5595 | mlog_errno(ret); |
5596 | goto out; | ||
5597 | } | ||
5426 | 5598 | ||
5427 | /* | 5599 | /* Ack, need more space. Let's try to get another bucket! */ |
5428 | * We do not allow for overlapping ranges between buckets. And | ||
5429 | * the maximum number of collisions we will allow for then is | ||
5430 | * one bucket's worth, so check it here whether we need to | ||
5431 | * add a new bucket for the insert. | ||
5432 | */ | ||
5433 | ret = ocfs2_check_xattr_bucket_collision(inode, | ||
5434 | xs->bucket, | ||
5435 | xi->name); | ||
5436 | if (ret) { | ||
5437 | mlog_errno(ret); | ||
5438 | goto out; | ||
5439 | } | ||
5440 | 5600 | ||
5441 | ret = ocfs2_add_new_xattr_bucket(inode, | 5601 | /* |
5442 | xs->xattr_bh, | 5602 | * We do not allow for overlapping ranges between buckets. And |
5603 | * the maximum number of collisions we will allow for then is | ||
5604 | * one bucket's worth, so check it here whether we need to | ||
5605 | * add a new bucket for the insert. | ||
5606 | */ | ||
5607 | ret = ocfs2_check_xattr_bucket_collision(inode, | ||
5443 | xs->bucket, | 5608 | xs->bucket, |
5444 | ctxt); | 5609 | xi->xi_name); |
5445 | if (ret) { | 5610 | if (ret) { |
5446 | mlog_errno(ret); | 5611 | mlog_errno(ret); |
5447 | goto out; | 5612 | goto out; |
5448 | } | 5613 | } |
5449 | 5614 | ||
5450 | /* | 5615 | ret = ocfs2_add_new_xattr_bucket(inode, |
5451 | * ocfs2_add_new_xattr_bucket() will have updated | 5616 | xs->xattr_bh, |
5452 | * xs->bucket if it moved, but it will not have updated | 5617 | xs->bucket, |
5453 | * any of the other search fields. Thus, we drop it and | 5618 | ctxt); |
5454 | * re-search. Everything should be cached, so it'll be | 5619 | if (ret) { |
5455 | * quick. | 5620 | mlog_errno(ret); |
5456 | */ | 5621 | goto out; |
5457 | ocfs2_xattr_bucket_relse(xs->bucket); | ||
5458 | ret = ocfs2_xattr_index_block_find(inode, xs->xattr_bh, | ||
5459 | xi->name_index, | ||
5460 | xi->name, xs); | ||
5461 | if (ret && ret != -ENODATA) | ||
5462 | goto out; | ||
5463 | xs->not_found = ret; | ||
5464 | allocation = 1; | ||
5465 | goto try_again; | ||
5466 | } | 5622 | } |
5467 | 5623 | ||
5468 | xattr_set: | 5624 | /* |
5469 | ret = ocfs2_xattr_set_in_bucket(inode, xi, xs, ctxt); | 5625 | * ocfs2_add_new_xattr_bucket() will have updated |
5626 | * xs->bucket if it moved, but it will not have updated | ||
5627 | * any of the other search fields. Thus, we drop it and | ||
5628 | * re-search. Everything should be cached, so it'll be | ||
5629 | * quick. | ||
5630 | */ | ||
5631 | ocfs2_xattr_bucket_relse(xs->bucket); | ||
5632 | ret = ocfs2_xattr_index_block_find(inode, xs->xattr_bh, | ||
5633 | xi->xi_name_index, | ||
5634 | xi->xi_name, xs); | ||
5635 | if (ret && ret != -ENODATA) | ||
5636 | goto out; | ||
5637 | xs->not_found = ret; | ||
5638 | |||
5639 | /* Ok, we have a new bucket, let's try again */ | ||
5640 | ret = ocfs2_xattr_set_entry_bucket(inode, xi, xs, ctxt); | ||
5641 | if (ret && (ret != -ENOSPC)) | ||
5642 | mlog_errno(ret); | ||
5643 | |||
5470 | out: | 5644 | out: |
5471 | mlog_exit(ret); | 5645 | mlog_exit(ret); |
5472 | return ret; | 5646 | return ret; |
@@ -5678,7 +5852,7 @@ static int ocfs2_prepare_refcount_xattr(struct inode *inode, | |||
5678 | * refcount tree, and make the original extent become 3. So we will need | 5852 | * refcount tree, and make the original extent become 3. So we will need |
5679 | * 2 * cluster more extent recs at most. | 5853 | * 2 * cluster more extent recs at most. |
5680 | */ | 5854 | */ |
5681 | if (!xi->value || xi->value_len <= OCFS2_XATTR_INLINE_SIZE) { | 5855 | if (!xi->xi_value || xi->xi_value_len <= OCFS2_XATTR_INLINE_SIZE) { |
5682 | 5856 | ||
5683 | ret = ocfs2_refcounted_xattr_delete_need(inode, | 5857 | ret = ocfs2_refcounted_xattr_delete_need(inode, |
5684 | &(*ref_tree)->rf_ci, | 5858 | &(*ref_tree)->rf_ci, |
@@ -6354,9 +6528,11 @@ static int ocfs2_create_empty_xattr_block(struct inode *inode, | |||
6354 | int indexed) | 6528 | int indexed) |
6355 | { | 6529 | { |
6356 | int ret; | 6530 | int ret; |
6357 | handle_t *handle; | ||
6358 | struct ocfs2_alloc_context *meta_ac; | 6531 | struct ocfs2_alloc_context *meta_ac; |
6359 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 6532 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
6533 | struct ocfs2_xattr_set_ctxt ctxt = { | ||
6534 | .meta_ac = meta_ac, | ||
6535 | }; | ||
6360 | 6536 | ||
6361 | ret = ocfs2_reserve_new_metadata_blocks(osb, 1, &meta_ac); | 6537 | ret = ocfs2_reserve_new_metadata_blocks(osb, 1, &meta_ac); |
6362 | if (ret < 0) { | 6538 | if (ret < 0) { |
@@ -6364,21 +6540,21 @@ static int ocfs2_create_empty_xattr_block(struct inode *inode, | |||
6364 | return ret; | 6540 | return ret; |
6365 | } | 6541 | } |
6366 | 6542 | ||
6367 | handle = ocfs2_start_trans(osb, OCFS2_XATTR_BLOCK_CREATE_CREDITS); | 6543 | ctxt.handle = ocfs2_start_trans(osb, OCFS2_XATTR_BLOCK_CREATE_CREDITS); |
6368 | if (IS_ERR(handle)) { | 6544 | if (IS_ERR(ctxt.handle)) { |
6369 | ret = PTR_ERR(handle); | 6545 | ret = PTR_ERR(ctxt.handle); |
6370 | mlog_errno(ret); | 6546 | mlog_errno(ret); |
6371 | goto out; | 6547 | goto out; |
6372 | } | 6548 | } |
6373 | 6549 | ||
6374 | mlog(0, "create new xattr block for inode %llu, index = %d\n", | 6550 | mlog(0, "create new xattr block for inode %llu, index = %d\n", |
6375 | (unsigned long long)fe_bh->b_blocknr, indexed); | 6551 | (unsigned long long)fe_bh->b_blocknr, indexed); |
6376 | ret = ocfs2_create_xattr_block(handle, inode, fe_bh, | 6552 | ret = ocfs2_create_xattr_block(inode, fe_bh, &ctxt, indexed, |
6377 | meta_ac, ret_bh, indexed); | 6553 | ret_bh); |
6378 | if (ret) | 6554 | if (ret) |
6379 | mlog_errno(ret); | 6555 | mlog_errno(ret); |
6380 | 6556 | ||
6381 | ocfs2_commit_trans(osb, handle); | 6557 | ocfs2_commit_trans(osb, ctxt.handle); |
6382 | out: | 6558 | out: |
6383 | ocfs2_free_alloc_context(meta_ac); | 6559 | ocfs2_free_alloc_context(meta_ac); |
6384 | return ret; | 6560 | return ret; |
diff --git a/fs/proc/kmsg.c b/fs/proc/kmsg.c index 7ca78346d3f0..cfe90a48a6e8 100644 --- a/fs/proc/kmsg.c +++ b/fs/proc/kmsg.c | |||
@@ -12,37 +12,37 @@ | |||
12 | #include <linux/poll.h> | 12 | #include <linux/poll.h> |
13 | #include <linux/proc_fs.h> | 13 | #include <linux/proc_fs.h> |
14 | #include <linux/fs.h> | 14 | #include <linux/fs.h> |
15 | #include <linux/syslog.h> | ||
15 | 16 | ||
16 | #include <asm/uaccess.h> | 17 | #include <asm/uaccess.h> |
17 | #include <asm/io.h> | 18 | #include <asm/io.h> |
18 | 19 | ||
19 | extern wait_queue_head_t log_wait; | 20 | extern wait_queue_head_t log_wait; |
20 | 21 | ||
21 | extern int do_syslog(int type, char __user *bug, int count); | ||
22 | |||
23 | static int kmsg_open(struct inode * inode, struct file * file) | 22 | static int kmsg_open(struct inode * inode, struct file * file) |
24 | { | 23 | { |
25 | return do_syslog(1,NULL,0); | 24 | return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_FILE); |
26 | } | 25 | } |
27 | 26 | ||
28 | static int kmsg_release(struct inode * inode, struct file * file) | 27 | static int kmsg_release(struct inode * inode, struct file * file) |
29 | { | 28 | { |
30 | (void) do_syslog(0,NULL,0); | 29 | (void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_FILE); |
31 | return 0; | 30 | return 0; |
32 | } | 31 | } |
33 | 32 | ||
34 | static ssize_t kmsg_read(struct file *file, char __user *buf, | 33 | static ssize_t kmsg_read(struct file *file, char __user *buf, |
35 | size_t count, loff_t *ppos) | 34 | size_t count, loff_t *ppos) |
36 | { | 35 | { |
37 | if ((file->f_flags & O_NONBLOCK) && !do_syslog(9, NULL, 0)) | 36 | if ((file->f_flags & O_NONBLOCK) && |
37 | !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE)) | ||
38 | return -EAGAIN; | 38 | return -EAGAIN; |
39 | return do_syslog(2, buf, count); | 39 | return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_FILE); |
40 | } | 40 | } |
41 | 41 | ||
42 | static unsigned int kmsg_poll(struct file *file, poll_table *wait) | 42 | static unsigned int kmsg_poll(struct file *file, poll_table *wait) |
43 | { | 43 | { |
44 | poll_wait(file, &log_wait, wait); | 44 | poll_wait(file, &log_wait, wait); |
45 | if (do_syslog(9, NULL, 0)) | 45 | if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE)) |
46 | return POLLIN | POLLRDNORM; | 46 | return POLLIN | POLLRDNORM; |
47 | return 0; | 47 | return 0; |
48 | } | 48 | } |
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 70504fcf14cd..14dafd608230 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h | |||
@@ -245,7 +245,7 @@ typedef struct xfs_mount { | |||
245 | struct xfs_qmops *m_qm_ops; /* vector of XQM ops */ | 245 | struct xfs_qmops *m_qm_ops; /* vector of XQM ops */ |
246 | atomic_t m_active_trans; /* number trans frozen */ | 246 | atomic_t m_active_trans; /* number trans frozen */ |
247 | #ifdef HAVE_PERCPU_SB | 247 | #ifdef HAVE_PERCPU_SB |
248 | xfs_icsb_cnts_t *m_sb_cnts; /* per-cpu superblock counters */ | 248 | xfs_icsb_cnts_t __percpu *m_sb_cnts; /* per-cpu superblock counters */ |
249 | unsigned long m_icsb_counters; /* disabled per-cpu counters */ | 249 | unsigned long m_icsb_counters; /* disabled per-cpu counters */ |
250 | struct notifier_block m_icsb_notifier; /* hotplug cpu notifier */ | 250 | struct notifier_block m_icsb_notifier; /* hotplug cpu notifier */ |
251 | struct mutex m_icsb_mutex; /* balancer sync lock */ | 251 | struct mutex m_icsb_mutex; /* balancer sync lock */ |