assise icon indicating copy to clipboard operation
assise copied to clipboard

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

Open cyber-punk20 opened this issue 4 years ago • 2 comments

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;
}

cyber-punk20 avatar Nov 06 '21 04:11 cyber-punk20

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().

wreda avatar Nov 06 '21 17:11 wreda

Thanks!

cyber-punk20 avatar Nov 06 '21 21:11 cyber-punk20