fs/nilfs2/cpfile.c

Source file repositories/reference/linux-study-clean/fs/nilfs2/cpfile.c

File Facts

System
Linux kernel
Corpus path
fs/nilfs2/cpfile.c
Extension
.c
Size
32412 bytes
Lines
1173
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

if (ret < 0) {
			if (ret != -ENOENT)
				break;
			/* skip hole */
			ret = 0;
			continue;
		}

		offset = nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh);
		cp = kaddr = kmap_local_folio(cp_bh->b_folio, offset);
		nicps = 0;
		for (i = 0; i < ncps; i++, cp = (void *)cp + cpsz) {
			if (nilfs_checkpoint_snapshot(cp)) {
				nss++;
			} else if (!nilfs_checkpoint_invalid(cp)) {
				nilfs_checkpoint_set_invalid(cp);
				nicps++;
			}
		}
		kunmap_local(kaddr);

		if (nicps <= 0) {
			brelse(cp_bh);
			continue;
		}

		tnicps += nicps;
		mark_buffer_dirty(cp_bh);
		nilfs_mdt_mark_dirty(cpfile);
		if (nilfs_cpfile_is_in_first(cpfile, cno)) {
			brelse(cp_bh);
			continue;
		}

		count = nilfs_cpfile_block_sub_valid_checkpoints(cpfile, cp_bh,
								 nicps);
		brelse(cp_bh);
		if (count)
			continue;

		/* Delete the block if there are no more valid checkpoints */
		ret = nilfs_cpfile_delete_checkpoint_block(cpfile, cno);
		if (unlikely(ret)) {
			nilfs_err(cpfile->i_sb,
				  "error %d deleting checkpoint block", ret);
			break;
		}
	}

	if (tnicps > 0) {
		header = kmap_local_folio(header_bh->b_folio, 0);
		le64_add_cpu(&header->ch_ncheckpoints, -(u64)tnicps);
		mark_buffer_dirty(header_bh);
		nilfs_mdt_mark_dirty(cpfile);
		kunmap_local(header);
	}

	brelse(header_bh);
	if (nss > 0)
		ret = -EBUSY;

 out_sem:
	up_write(&NILFS_MDT(cpfile)->mi_sem);
	return ret;
}

static void nilfs_cpfile_checkpoint_to_cpinfo(struct inode *cpfile,
					      struct nilfs_checkpoint *cp,
					      struct nilfs_cpinfo *ci)
{
	ci->ci_flags = le32_to_cpu(cp->cp_flags);
	ci->ci_cno = le64_to_cpu(cp->cp_cno);
	ci->ci_create = le64_to_cpu(cp->cp_create);
	ci->ci_nblk_inc = le64_to_cpu(cp->cp_nblk_inc);
	ci->ci_inodes_count = le64_to_cpu(cp->cp_inodes_count);
	ci->ci_blocks_count = le64_to_cpu(cp->cp_blocks_count);
	ci->ci_next = le64_to_cpu(cp->cp_snapshot_list.ssl_next);
}

static ssize_t nilfs_cpfile_do_get_cpinfo(struct inode *cpfile, __u64 *cnop,
					  void *buf, unsigned int cisz,
					  size_t nci)
{
	struct nilfs_checkpoint *cp;
	struct nilfs_cpinfo *ci = buf;
	struct buffer_head *bh;
	size_t cpsz = NILFS_MDT(cpfile)->mi_entry_size;
	__u64 cur_cno = nilfs_mdt_cno(cpfile), cno = *cnop;
	size_t offset;
	void *kaddr;

Annotation

Implementation Notes