Get the App
SLTechnology News&Howtos  ›  Servers  › 

The usage of blk function in linux

Shulou Source: shulou.com Published: 2022-06-01 14:54:49 09月27日 Update

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!

Tags: Functions content pointers data more knowledge learning updating practicality learning and then code functions commands dilemmas actually that is situations points files. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Apple Shulou Tech Info MariaDB Xiaomi