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

The usage of blk function in linux

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "the usage of blk function in linux". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Linux block level learning 1. Functions in blk-map.c code blk_rq_append_bioint blk_rq_append_bio (struct request * rq, struct bio * bio) {if (! rq- > bio) {/ / yyf: blk_rq_bio_prep without bio in rq (rq- > Q, rq, bio) } else {if (! ll_back_merge_fn (rq- > Q, rq, bio) return-EINVAL; rq- > biotail- > bi_next = bio; rq- > biotail = bio; rq- > _ _ data_len + = bio- > bi_iter.bi_size;} return 0 } EXPORT_SYMBOL (blk_rq_append_bio)

The function of blk_rq_append_bio is to hang a bio to rq. If bio already exists in rq, update the bi_next pointer of the last bio pointed to by rq- > biotail directly, and update the biotail pointer and _ _ data_len length.

When there is no bio in rq, execute the blk_rq_bio_prep function:

Void blk_rq_bio_prep (struct request_queue * Q, struct request * rq, struct bio * bio) {if (bio_has_data (bio)) / / yyf: if there is data, the nr_phys_segments rq- > nr_phys_segments = bio_phys_segments (Q, bio) of the assignment rq; rq- > _ data_len = bio- > bi_iter.bi_size Rq- > bio = rq- > biotail = bio; / / yyf: bio hangs into the rq linked list if (bio- > bi_bdev) rq- > rq_disk = bio- > bi_bdev- > bd_disk;}

Bio_has_data determines whether the bio carries data, and inline defines it in the header file:

/ * Check whether this bio carries any data or not. A NULL bio is allowed. * / static inline bool bio_has_data (struct bio * bio) {if (bio & & bio- > bi_iter.bi_size & & bio_op (bio)! = REQ_OP_DISCARD & & bio_op (bio)! = REQ_OP_SECURE_ERASE & & bio_op (bio)! = REQ_OP_WRITE_ZEROES) return true; return false;}

The bio_has_data function is very simple, which is to determine whether bio exists, whether there is bi_size, and whether it satisfies certain operation commands.

This is the end of the introduction to "the use of blk function in linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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