Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:block\partition-generic.c Create Date:2022-07-28 17:21:10
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:Must be called either with bd_mutex held, before a disk can be opened or* after all disk users are gone.

Proto:struct hd_struct *add_partition(struct gendisk *disk, int partno, sector_t start, sector_t len, int flags, struct partition_meta_info *info)

Type:struct hd_struct

Parameter:

TypeParameterName
struct gendisk *disk
intpartno
sector_tstart
sector_tlen
intflags
struct partition_meta_info *info
317  devt = MKDEV(0, 0)
318  ddev = disk_to_dev(disk)
329  Case zoned == Host-managed zoned block device
330  pr_warn("%s: partitions not supported on host managed zoned block device\n", name of major driver )
332  Return ERR_PTR( - ENXIO)
333  Case zoned == Host-aware zoned block device
334  pr_info("%s: disabling host aware zoned block device support due to partitions\n", name of major driver )
336  zoned = Regular block device
337  Break
338  Case zoned == Regular block device
339  Break
342  err = disk_expand_part_tbl - expand disk->part_tbl*@disk: disk to expand part_tbl for*@partno: expand such that this partno can fit in* Expand disk->part_tbl such that @partno can fit in. disk->part_tbl
343  If err Then Return ERR_PTR(err)
345  ptbl = cu_dereference_protected() - fetch RCU pointer when updates prevented*@p: The pointer to read, prior to dereferencing*@c: The conditions under which the dereference will take place* Return the value of the specified RCU-protected pointer, but omit( Array of pointers to partitions indexed by partno. * Protected with matching bdev lock but stat and other * non-critical accesses use RCU. Always access through * helpers., 1)
347  If part[partno] Then Return ERR_PTR( - EBUSY)
350  p = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc).
351  If Not p Then Return ERR_PTR( - EBUSY)
354  If Not init_part_stats(p) Then
355  err = -ENOMEM
356  Go to out_free
359  seqcount_init( & nr_sects_seq)
360  pdev = part_to_dev(p)
362  start_sect = start
363  alignment_offset = queue_limit_alignment_offset( & limits, start)
365  discard_alignment = queue_limit_discard_alignment( & limits, start)
367  * nr_sects is protected by sequence counter. One might extend a * partition while IO is happening to it and update of nr_sects * can be non-atomic on 32bit machines with 64bit sector_t. = len
368  partno = partno
369  policy = get_disk_ro(disk)
371  If info Then
372  pinfo = alloc_part_info(disk)
373  If Not pinfo Then
374  err = -ENOMEM
375  Go to out_free_stats
377  memcpy(pinfo, info, size of info )
378  info = pinfo
381  dname = dev_name(ddev)
382  If isdigit(dname[strlen - Find the length of a string*@s: The string to be sized - 1]) Then dev_set_name(pdev, "%sp%d", dname, partno)
384  Else dev_set_name(pdev, "%s%d", dname, partno)
387  device_initialize(pdev)
388  class = block_class
389  type = part_type
390  parent = ddev
392  err = lk_alloc_devt - allocate a dev_t for a partition*@part: partition to allocate dev_t for*@devt: out parameter for resulting dev_t* Allocate a dev_t for block device
393  If err Then Go to out_free_info
395  dev_t, creates the sysfs "dev" = devt
398  dev_set_uevent_suppress(pdev, 1)
399  err = device_add(pdev)
400  If err Then Go to out_put
403  err = -ENOMEM
404  holder_dir = kobject_create_and_add() - Create a struct kobject dynamically and* register it with sysfs.*@name: the name for the kobject*@parent: the parent kobject of this kobject, if any.* This function creates a kobject structure dynamically and registers it
405  If Not holder_dir Then Go to out_del
408  dev_set_uevent_suppress(pdev, 0)
409  If flags & ADDPART_FLAG_WHOLEDISK Then
410  err = device_create_file(pdev, & dev_attr_whole_disk)
411  If err Then Go to out_del
415  err = hd_ref_init(p)
416  If err Then
417  If flags & ADDPART_FLAG_WHOLEDISK Then Go to out_remove_file
419  Go to out_del
423  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization(part[partno], p)
426  If Not dev_get_uevent_suppress(ddev) Then kobject_uevent - notify userspace by sending an uevent*@kobj: struct kobject that the action is happening to*@action: action that is happening* Returns 0 if kobject_uevent() is completed with success or the* corresponding error when it fails.
428  Return p
430  out_free_info :
431  free_part_info(p)
432  out_free_stats :
433  free_part_stats(p)
434  out_free :
435  kfree(p)
436  Return ERR_PTR(err)
437  out_remove_file :
438  device_remove_file(pdev, & dev_attr_whole_disk)
439  out_del :
440  kobject_put() - Decrement refcount for object.*@kobj: object.* Decrement the refcount, and if 0, call kobject_cleanup().
441  device_del(pdev)
442  out_put :
443  put_device(pdev)
444  Return ERR_PTR(err)
Caller
NameDescribe
blk_add_partition