Lines Matching refs:vol

58 	struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);  in vol_attribute_show()  local
59 struct ubi_device *ubi = vol->ubi; in vol_attribute_show()
62 if (!ubi->volumes[vol->vol_id] || ubi->volumes[vol->vol_id]->is_dead) { in vol_attribute_show()
67 vol->ref_count += 1; in vol_attribute_show()
71 ret = sprintf(buf, "%d\n", vol->reserved_pebs); in vol_attribute_show()
75 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in vol_attribute_show()
81 ret = sprintf(buf, "%s\n", vol->name); in vol_attribute_show()
83 ret = sprintf(buf, "%d\n", vol->corrupted); in vol_attribute_show()
85 ret = sprintf(buf, "%d\n", vol->alignment); in vol_attribute_show()
87 ret = sprintf(buf, "%d\n", vol->usable_leb_size); in vol_attribute_show()
89 ret = sprintf(buf, "%lld\n", vol->used_bytes); in vol_attribute_show()
91 ret = sprintf(buf, "%d\n", vol->upd_marker); in vol_attribute_show()
98 vol->ref_count -= 1; in vol_attribute_show()
99 ubi_assert(vol->ref_count >= 0); in vol_attribute_show()
120 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); in vol_release() local
122 ubi_eba_replace_table(vol, NULL); in vol_release()
123 ubi_fastmap_destroy_checkmap(vol); in vol_release()
124 kfree(vol); in vol_release()
127 static struct fwnode_handle *find_volume_fwnode(struct ubi_volume *vol) in find_volume_fwnode() argument
133 fw_vols = device_get_named_child_node(vol->dev.parent->parent, "volumes"); in find_volume_fwnode()
139 strncmp(volname, vol->name, vol->name_len)) in find_volume_fwnode()
143 vol->vol_id != volid) in find_volume_fwnode()
168 struct ubi_volume *vol; in ubi_create_volume() local
175 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL); in ubi_create_volume()
176 if (!vol) in ubi_create_volume()
179 device_initialize(&vol->dev); in ubi_create_volume()
180 vol->dev.release = vol_release; in ubi_create_volume()
181 vol->dev.parent = &ubi->dev; in ubi_create_volume()
182 vol->dev.class = &ubi_class; in ubi_create_volume()
183 vol->dev.groups = volume_dev_groups; in ubi_create_volume()
186 vol->skip_check = 1; in ubi_create_volume()
228 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment; in ubi_create_volume()
229 vol->reserved_pebs = div_u64(req->bytes + vol->usable_leb_size - 1, in ubi_create_volume()
230 vol->usable_leb_size); in ubi_create_volume()
233 if (vol->reserved_pebs > ubi->avail_pebs) { in ubi_create_volume()
242 ubi->avail_pebs -= vol->reserved_pebs; in ubi_create_volume()
243 ubi->rsvd_pebs += vol->reserved_pebs; in ubi_create_volume()
246 vol->vol_id = vol_id; in ubi_create_volume()
247 vol->alignment = req->alignment; in ubi_create_volume()
248 vol->data_pad = ubi->leb_size % vol->alignment; in ubi_create_volume()
249 vol->vol_type = req->vol_type; in ubi_create_volume()
250 vol->name_len = req->name_len; in ubi_create_volume()
251 memcpy(vol->name, req->name, vol->name_len); in ubi_create_volume()
252 vol->ubi = ubi; in ubi_create_volume()
253 device_set_node(&vol->dev, find_volume_fwnode(vol)); in ubi_create_volume()
263 eba_tbl = ubi_eba_create_table(vol, vol->reserved_pebs); in ubi_create_volume()
269 ubi_eba_replace_table(vol, eba_tbl); in ubi_create_volume()
271 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_create_volume()
272 vol->used_ebs = vol->reserved_pebs; in ubi_create_volume()
273 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
274 vol->used_bytes = in ubi_create_volume()
275 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_create_volume()
277 vol->used_ebs = div_u64_rem(vol->used_bytes, in ubi_create_volume()
278 vol->usable_leb_size, in ubi_create_volume()
279 &vol->last_eb_bytes); in ubi_create_volume()
280 if (vol->last_eb_bytes != 0) in ubi_create_volume()
281 vol->used_ebs += 1; in ubi_create_volume()
283 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
288 ubi->volumes[vol_id] = vol; in ubi_create_volume()
293 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_create_volume()
294 vol->cdev.owner = THIS_MODULE; in ubi_create_volume()
296 vol->dev.devt = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); in ubi_create_volume()
297 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_create_volume()
298 err = cdev_device_add(&vol->cdev, &vol->dev); in ubi_create_volume()
306 vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs); in ubi_create_volume()
307 vtbl_rec.alignment = cpu_to_be32(vol->alignment); in ubi_create_volume()
308 vtbl_rec.data_pad = cpu_to_be32(vol->data_pad); in ubi_create_volume()
309 vtbl_rec.name_len = cpu_to_be16(vol->name_len); in ubi_create_volume()
310 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in ubi_create_volume()
315 if (vol->skip_check) in ubi_create_volume()
318 memcpy(vtbl_rec.name, vol->name, vol->name_len); in ubi_create_volume()
324 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); in ubi_create_volume()
334 cdev_device_del(&vol->cdev, &vol->dev); in ubi_create_volume()
342 ubi->rsvd_pebs -= vol->reserved_pebs; in ubi_create_volume()
343 ubi->avail_pebs += vol->reserved_pebs; in ubi_create_volume()
346 put_device(&vol->dev); in ubi_create_volume()
363 struct ubi_volume *vol = desc->vol; in ubi_remove_volume() local
364 struct ubi_device *ubi = vol->ubi; in ubi_remove_volume()
365 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs; in ubi_remove_volume()
369 ubi_assert(vol == ubi->volumes[vol_id]); in ubi_remove_volume()
375 if (vol->ref_count > 1) { in ubi_remove_volume()
390 vol->is_dead = true; in ubi_remove_volume()
393 ubi_volume_notify(ubi, vol, UBI_VOLUME_SHUTDOWN); in ubi_remove_volume()
405 for (i = 0; i < vol->reserved_pebs; i++) { in ubi_remove_volume()
406 err = ubi_eba_unmap_leb(ubi, vol, i); in ubi_remove_volume()
411 cdev_device_del(&vol->cdev, &vol->dev); in ubi_remove_volume()
412 put_device(&vol->dev); in ubi_remove_volume()
421 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED); in ubi_remove_volume()
430 ubi->volumes[vol_id] = vol; in ubi_remove_volume()
448 struct ubi_volume *vol = desc->vol; in ubi_resize_volume() local
449 struct ubi_device *ubi = vol->ubi; in ubi_resize_volume()
453 int vol_id = vol->vol_id; in ubi_resize_volume()
459 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs); in ubi_resize_volume()
461 if (vol->vol_type == UBI_STATIC_VOLUME && in ubi_resize_volume()
462 reserved_pebs < vol->used_ebs) { in ubi_resize_volume()
464 reserved_pebs, vol->used_ebs); in ubi_resize_volume()
469 if (reserved_pebs == vol->reserved_pebs) in ubi_resize_volume()
472 new_eba_tbl = ubi_eba_create_table(vol, reserved_pebs); in ubi_resize_volume()
477 if (vol->ref_count > 1) { in ubi_resize_volume()
485 pebs = reserved_pebs - vol->reserved_pebs; in ubi_resize_volume()
501 ubi_eba_copy_table(vol, new_eba_tbl, vol->reserved_pebs); in ubi_resize_volume()
502 old_eba_tbl = vol->eba_tbl; in ubi_resize_volume()
503 vol->eba_tbl = new_eba_tbl; in ubi_resize_volume()
504 vol->reserved_pebs = reserved_pebs; in ubi_resize_volume()
510 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i); in ubi_resize_volume()
518 ubi_eba_copy_table(vol, new_eba_tbl, reserved_pebs); in ubi_resize_volume()
519 old_eba_tbl = vol->eba_tbl; in ubi_resize_volume()
520 vol->eba_tbl = new_eba_tbl; in ubi_resize_volume()
521 vol->reserved_pebs = reserved_pebs; in ubi_resize_volume()
543 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_resize_volume()
544 vol->used_ebs = reserved_pebs; in ubi_resize_volume()
545 vol->last_eb_bytes = vol->usable_leb_size; in ubi_resize_volume()
546 vol->used_bytes = in ubi_resize_volume()
547 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_resize_volume()
552 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); in ubi_resize_volume()
558 vol->reserved_pebs = reserved_pebs - pebs; in ubi_resize_volume()
562 ubi_eba_copy_table(vol, old_eba_tbl, vol->reserved_pebs); in ubi_resize_volume()
564 ubi_eba_copy_table(vol, old_eba_tbl, reserved_pebs); in ubi_resize_volume()
565 vol->eba_tbl = old_eba_tbl; in ubi_resize_volume()
596 struct ubi_volume *vol = re->desc->vol; in ubi_rename_volumes() local
599 vol->name_len = re->new_name_len; in ubi_rename_volumes()
600 memcpy(vol->name, re->new_name, re->new_name_len + 1); in ubi_rename_volumes()
602 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED); in ubi_rename_volumes()
620 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_add_volume() argument
622 int err, vol_id = vol->vol_id; in ubi_add_volume()
628 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_add_volume()
629 vol->cdev.owner = THIS_MODULE; in ubi_add_volume()
630 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1); in ubi_add_volume()
631 err = cdev_add(&vol->cdev, dev, 1); in ubi_add_volume()
635 vol_release(&vol->dev); in ubi_add_volume()
639 vol->dev.release = vol_release; in ubi_add_volume()
640 vol->dev.parent = &ubi->dev; in ubi_add_volume()
641 vol->dev.devt = dev; in ubi_add_volume()
642 vol->dev.class = &ubi_class; in ubi_add_volume()
643 vol->dev.groups = volume_dev_groups; in ubi_add_volume()
644 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_add_volume()
645 device_set_node(&vol->dev, find_volume_fwnode(vol)); in ubi_add_volume()
646 err = device_register(&vol->dev); in ubi_add_volume()
648 cdev_del(&vol->cdev); in ubi_add_volume()
649 put_device(&vol->dev); in ubi_add_volume()
665 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_free_volume() argument
667 dbg_gen("free volume %d", vol->vol_id); in ubi_free_volume()
669 ubi->volumes[vol->vol_id] = NULL; in ubi_free_volume()
670 cdev_del(&vol->cdev); in ubi_free_volume()
671 device_unregister(&vol->dev); in ubi_free_volume()
685 const struct ubi_volume *vol; in self_check_volume() local
691 vol = ubi->volumes[idx]; in self_check_volume()
693 if (!vol) { in self_check_volume()
702 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 || in self_check_volume()
703 vol->name_len < 0) { in self_check_volume()
707 if (vol->alignment > ubi->leb_size || vol->alignment == 0) { in self_check_volume()
712 n = vol->alignment & (ubi->min_io_size - 1); in self_check_volume()
713 if (vol->alignment != 1 && n) { in self_check_volume()
718 n = ubi->leb_size % vol->alignment; in self_check_volume()
719 if (vol->data_pad != n) { in self_check_volume()
724 if (vol->vol_type != UBI_DYNAMIC_VOLUME && in self_check_volume()
725 vol->vol_type != UBI_STATIC_VOLUME) { in self_check_volume()
730 if (vol->upd_marker && vol->corrupted) { in self_check_volume()
735 if (vol->reserved_pebs > ubi->good_peb_count) { in self_check_volume()
740 n = ubi->leb_size - vol->data_pad; in self_check_volume()
741 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) { in self_check_volume()
746 if (vol->name_len > UBI_VOL_NAME_MAX) { in self_check_volume()
752 n = strnlen(vol->name, vol->name_len + 1); in self_check_volume()
753 if (n != vol->name_len) { in self_check_volume()
758 n = (long long)vol->used_ebs * vol->usable_leb_size; in self_check_volume()
759 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in self_check_volume()
760 if (vol->corrupted) { in self_check_volume()
764 if (vol->used_ebs != vol->reserved_pebs) { in self_check_volume()
768 if (vol->last_eb_bytes != vol->usable_leb_size) { in self_check_volume()
772 if (vol->used_bytes != n) { in self_check_volume()
777 if (vol->skip_check) { in self_check_volume()
782 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) { in self_check_volume()
786 if (vol->last_eb_bytes < 0 || in self_check_volume()
787 vol->last_eb_bytes > vol->usable_leb_size) { in self_check_volume()
791 if (vol->used_bytes < 0 || vol->used_bytes > n || in self_check_volume()
792 vol->used_bytes < n - vol->usable_leb_size) { in self_check_volume()
808 if (alignment != vol->alignment || data_pad != vol->data_pad || in self_check_volume()
809 upd_marker != vol->upd_marker || vol_type != vol->vol_type || in self_check_volume()
810 name_len != vol->name_len || strncmp(name, vol->name, name_len)) { in self_check_volume()
820 if (vol) in self_check_volume()
821 ubi_dump_vol_info(vol); in self_check_volume()