Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Cephfs kernel client operation code for opening files

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article is to share with you about the operation code of cephfs kernel client for opening files. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The operation to open a file is mainly reflected in the struct file_operations data structure. The specific implementation in cephfs kernel client is as follows:

Const struct file_operations ceph_file_fops = {

.open = ceph_open

.release = ceph_release

.llcards = ceph_llseek

.read _ iter = ceph_read_iter

.write _ iter = ceph_write_iter

.mmap = ceph_mmap

.fsync = ceph_fsync

.lock = ceph_lock

.flock = ceph_flock

.splice _ read = generic_file_splice_read

.splice _ write = iter_file_splice_write

.unloaded _ ioctl = ceph_ioctl

.compat _ ioctl = ceph_ioctl

.falsely = ceph_fallocate

}

Ceph_open (struct inode * inode, struct file * file) this function is called when the file is opened

| | _ _ call the prepare_open_request () function to create a ceph_mds_request request |

| | _ _ call ceph_mdsc_do_request () function to send the ceph_mds_request request to the mds process synchronously |

| | _ _ call the ceph_init_file () function to create a ceph_file_info data structure and put the data structure into file- > private_data |

Ceph_release (struct inode * inode, struct file * file) this function is called when the file is closed

| | _ _ call the ceph_put_fmode () function to reduce the number of references to a file. If the number of references is 0, the file will be deleted from the local cache. |

Ceph_llseek (struct file * file, loff_t offset, int whence)

| | _ if whence is SEEK_END | SEEK_DATA | SEEK_HOLE |

| | _ _ call the ceph_do_getattr () function to obtain the attrs attribute of the specified inode from the mds cluster |

| | _ _ call i_size_read () function to get the actual size of the current inode |

| | _ _ adjust the value of offset according to the value of whence |

| | _ _ call the vfs_setpos () function to set the current location of the file to offset |

Ceph_read_iter (struct kiocb * iocb, struct iov_iter * to) this function is called when reading the contents of the file

| | _ _ call ceph_get_caps () function to get caps |

| | _ _ for synchronous data reading operations |

| | _ _ if iocb-> ki_flags&IOCB_DIRECT |

| | _ _ call the ceph_direct_read_write () function to read data from the osds cluster |

| | _ if! iocb- > ki_flags&IOCB_DIRECT |

| | _ _ call the ceph_sync_read () function to read data from the osds cluster |

| | _ _ for asynchronous data reading operations |

| | _ _ call generic_file_read_iter () function to read asynchronous data |

This function is called when ceph_write_iter (structd kiocb * iocb, struct iov_iter * from) performs a write operation.

| | _ _ call the generic_write_check () function to do necessary checks before actually writing |

| | _ _ call ceph_get_caps () to get write permission |

| | _ for synchronous write operations |

| | _ _ for iocb- > ki_flags & IOCB_DIRECT |

| | _ _ call ceph_direct_read_write () function to write data to osds cluster |

| _ _ for! Iocb- > ki_flags & IOCB_DIRECT

| | _ _ call the ceph_sync_write () function to write data to red in the osds cluster |

| | _ _ for asynchronous write operations |

| | _ _ call generic_perform_write () function to perform write operation |

This function is called when ceph_mmap (struct file * file, struct vm_area_struct * vma) maps the contents of a file to memory.

| | _ _ sets the vm_ops=ceph_vmops of vma |

Ceph_fsync (struct file * file, loff_t start, loff_t end, int datasync)

| | _ _ call the ceph_sync_write_wait () function to wait for the execution of all outstanding osd requests on inode. |

| | _ _ call the try_flush_caps () function to brush the caps of all dirty back to mds |

| | _ _ call the unsafe_request_wait () function to wait for the execution of all mds requests on the inode. |

Ceph_lock (struct file * file, int cmd, struct file_lock * fl) calls this function when a user-mode program executes fcntl lock.

| | _ _ after calling the ceph_lock_message () function to create a file lock command request, send the request to the mds cluster |

Ceph_flock (struct file * file, int cmd, struct file_lock * fl)

| | _ _ after calling the ceph_lock_message () function to create a file lock command request, send the request to the mds cluster |

Ceph_ioctl (struct file * file, unsigned int cmd, unsigned long arg)

| | _ _ do different processing according to the value of cmd |

| | _ cmd==CEPH_IOC_GET_LAYOUT |

| | _ ceph_ioctl_get_layout () |

| | _ _ ceph_do_getattr (CEPH_STAT_CAP_LAYOUT) reads the layout information of the inode corresponding to file from the mds cluster to the i_layout of ceph_inode_info |

| | _ _ write the i_layout information to the struct ceph_ioctl_layout data structure and return the data to the user state through the copy_to_user () function |

| | _ cmd==CEPH_IOC_SET_LAYOUT |

| | _ ceph_ioctl_set_layout () |

| | _ _ call the copy_from_user () function to copy the new layout information from user mode to kernel mode |

| | _ _ call ceph_do_getattr () function to read the current layout information from the mds cluster |

| | _ _ call _ _ validate_layout () function to check whether the newly set layout is valid |

| | _ _ call the ceph_mdsc_create_request () function to create a request request |

| | _ _ call the ceph_mdsc_do_request () function to send a request request to the mds cluster synchronously |

| | _ cmd==CEPH_IOC_SET_LAYOUT_POLICY |

| | _ ceph_ioctl_set_layout_policy () |

| | _ _ call the copy_from_user () function to copy the new layout information from user mode to kernel mode |

| | _ _ call _ _ validate_layout () function to check whether the newly set layout is valid |

| | _ _ call the ceph_mdsc_create_request () function to create a request request |

| | _ _ call the ceph_mdsc_do_request () function to send a request request to the mds cluster synchronously |

| | _ _ cmd==CEPH_IOC_GET_DATALOC calculates the location information in the ceph cluster where the data resides |

| | _ ceph_ioctl_get_dataloc () |

| | _ _ call copy_from_user () function to copy ceph_ioctl_dataloc information to kernel state |

| | _ _ call the ceph_calc_file_object_mapping () function to calculate the oid and other information of the specified file in the ceph_ioctl_dataloc information |

| | _ _ call the ceph_object_locator_to_pg () function to calculate the pg information where the oid is located |

| | _ _ call the ceph_pg_to_acting_primary () function to calculate the information of the main osd where the pg is located |

| | _ _ call the copy_to_user () function to send the calculated information back to the user state |

| | _ _ cmd==CEPH_IOC_LAZYIO sets the LAZYIO ID |

| | _ ceph_ioctl_lazyio () |

| | _ _ determines whether the fmode in struct ceph_file_info does not have CEPH_FILE_MODE_LAZY set |

| | _ _ sets the fmode in struct ceph_file_info to have the CEPH_FILE_MODE_LAZY ID |

| | _ _ update the i_nr_by_mode array in ceph_inode_info |

| | _ _ call ceph_check_caps () function to update caps |

| | _ cmd==CEPH_IOC_SYNCIO |

| | _ ceph_ioctl_syncio () |

| | _ _ sets the CEPH_F_ sync bit of flags in struct ceph_file_info structure |

Ceph_fallocate (struct file * file, int mode, loff_t offset, loff_t length)

| | _ _ if mode = = FALLOC_FL_PUNCH_HOLE |

| | _ _ call the ceph_zero_object () function to set the file content to 0 from the specified offset to the end of the offset+length. |

| | offset+length > size |

| | _ _ call ceph_inode_set_size () to set the file size to offset+length |

| | _ _ call the ceph_check_caps () function to verify whether the authentication of the file caps is valid |

The operations related to the mapping of files to memory are mainly reflected in the struct vm_operations_struct data structure, as follows:

Static const struct vm_operations_struct ceph_vmops = {

.fault = ceph_filemap_fault

.page _ mkwrite = ceph_page_mkwrite

}

Ceph_filemap_fault (struct vm_area_struct * vma, struct vm_fault * vmf) this function is called when a memory page fault occurs while reading data in memory

| | _ _ call find_or_create_page () function to get the physical memory page from physical memory |

| | _ _ call _ _ ceph_do_getattr (CEPH_STAT_CAP_INLINE_DATA) function to read data from mds cluster |

| | _ _ call flush_dcache_page () function to write the read data to the physical memory page |

| | _ _ call the SetPageUptodate () function to set the physical memory page has been updated |

| | _ _ set vmf- > page=page, that is, add physical memory pages to virtual memory |

Ceph_page_mkwrite (struct vm_area_struct * vma, struct vm_fault * vmf) this function is called when the page transitions from readonly state to writeable state

| | _ _ call ceph_update_writeable_page () function to set vmf- > page page to writeable |

| | _ _ call the set_page_diry () function to set the physical memory page to dirty |

Thank you for reading! On "cephfs kernel client operation code for opening files" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report