Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused about function compute_log_blocks in libfs/src/log/log.c #15

Open
cyber-punk20 opened this issue Nov 6, 2021 · 2 comments
Open

Comments

@cyber-punk20
Copy link

Hi folks,
When we're reading the function compute_log_blocks in libfs/src/log/log.c, we're confused about the code in case L_TYPE_FILE. For the else case, if size is 3.5 g_block_size, then after shift, only 3 blocks will be added. However, according to our understanding, 4 blocks should be added. Would you mind explaining to us? Thanks!

static uint32_t compute_log_blocks(struct logheader_meta *loghdr_meta)
{
	  struct logheader *loghdr = loghdr_meta->loghdr; 
	  uint8_t type, n_iovec; 
	  uint32_t nr_log_blocks = 0;
	  int i;
	  for (i = 0, n_iovec = 0; i < loghdr->n; i++) {
		  type = loghdr->type[i];
  
		  switch(type) {
			  case L_TYPE_UNLINK:
			  case L_TYPE_INODE_CREATE:
			  case L_TYPE_INODE_UPDATE:
			  case L_TYPE_ALLOC: {
				  nr_log_blocks++;
				  break;
			  } 
			  case L_TYPE_DIR_ADD:
			  case L_TYPE_DIR_RENAME:
			  case L_TYPE_DIR_DEL:
			  case L_TYPE_FILE: {
				  uint32_t size;
				  size = loghdr_meta->io_vec[n_iovec].size;
  
				  if (size < g_block_size_bytes)
					  nr_log_blocks++;
				  else
					  nr_log_blocks += 
						  (size >> g_block_size_shift);
				  n_iovec++;
				  break;
			  }
			  default: {
				  panic("unsupported log type\n");
				  break;
			  }
		  }
	  }
	  return nr_log_blocks;
}
@wreda
Copy link
Contributor

wreda commented Nov 6, 2021

The size can never be equal to 3.5 * g_block_size_bytes. It's first broken down into aligned and unaligned portions (see: mlfs_file_write) which are added to the log via separate invocations of add_to_log().

@cyber-punk20
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants