Lines Matching refs:ubi
19 static int self_check_volumes(struct ubi_device *ubi);
59 struct ubi_device *ubi = vol->ubi; in vol_attribute_show() local
61 spin_lock(&ubi->volumes_lock); in vol_attribute_show()
62 if (!ubi->volumes[vol->vol_id]) { in vol_attribute_show()
63 spin_unlock(&ubi->volumes_lock); in vol_attribute_show()
68 spin_unlock(&ubi->volumes_lock); in vol_attribute_show()
97 spin_lock(&ubi->volumes_lock); in vol_attribute_show()
100 spin_unlock(&ubi->volumes_lock); in vol_attribute_show()
138 int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) in ubi_create_volume() argument
145 if (ubi->ro_mode) in ubi_create_volume()
154 vol->dev.parent = &ubi->dev; in ubi_create_volume()
161 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
165 for (i = 0; i < ubi->vtbl_slots; i++) in ubi_create_volume()
166 if (!ubi->volumes[i]) { in ubi_create_volume()
172 ubi_err(ubi, "out of volume IDs"); in ubi_create_volume()
180 ubi->ubi_num, vol_id, (unsigned long long)req->bytes, in ubi_create_volume()
185 if (ubi->volumes[vol_id]) { in ubi_create_volume()
186 ubi_err(ubi, "volume %d already exists", vol_id); in ubi_create_volume()
191 for (i = 0; i < ubi->vtbl_slots; i++) in ubi_create_volume()
192 if (ubi->volumes[i] && in ubi_create_volume()
193 ubi->volumes[i]->name_len == req->name_len && in ubi_create_volume()
194 !strcmp(ubi->volumes[i]->name, req->name)) { in ubi_create_volume()
195 ubi_err(ubi, "volume \"%s\" exists (ID %d)", in ubi_create_volume()
201 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment; in ubi_create_volume()
206 if (vol->reserved_pebs > ubi->avail_pebs) { in ubi_create_volume()
207 ubi_err(ubi, "not enough PEBs, only %d available", in ubi_create_volume()
208 ubi->avail_pebs); in ubi_create_volume()
209 if (ubi->corr_peb_count) in ubi_create_volume()
210 ubi_err(ubi, "%d PEBs are corrupted and not used", in ubi_create_volume()
211 ubi->corr_peb_count); in ubi_create_volume()
215 ubi->avail_pebs -= vol->reserved_pebs; in ubi_create_volume()
216 ubi->rsvd_pebs += vol->reserved_pebs; in ubi_create_volume()
217 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
221 vol->data_pad = ubi->leb_size % vol->alignment; in ubi_create_volume()
225 vol->ubi = ubi; in ubi_create_volume()
231 err = ubi_wl_flush(ubi, vol_id, UBI_ALL); in ubi_create_volume()
259 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
260 ubi->volumes[vol_id] = vol; in ubi_create_volume()
261 ubi->vol_count += 1; in ubi_create_volume()
262 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
268 vol->dev.devt = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); in ubi_create_volume()
269 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_create_volume()
272 ubi_err(ubi, "cannot add device"); in ubi_create_volume()
292 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); in ubi_create_volume()
296 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); in ubi_create_volume()
297 self_check_volumes(ubi); in ubi_create_volume()
308 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
309 ubi->volumes[vol_id] = NULL; in ubi_create_volume()
310 ubi->vol_count -= 1; in ubi_create_volume()
311 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
313 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
314 ubi->rsvd_pebs -= vol->reserved_pebs; in ubi_create_volume()
315 ubi->avail_pebs += vol->reserved_pebs; in ubi_create_volume()
317 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
319 ubi_err(ubi, "cannot create volume %d, error %d", vol_id, err); in ubi_create_volume()
336 struct ubi_device *ubi = vol->ubi; in ubi_remove_volume() local
339 dbg_gen("remove device %d, volume %d", ubi->ubi_num, vol_id); in ubi_remove_volume()
341 ubi_assert(vol == ubi->volumes[vol_id]); in ubi_remove_volume()
343 if (ubi->ro_mode) in ubi_remove_volume()
346 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
355 ubi->volumes[vol_id] = NULL; in ubi_remove_volume()
356 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
359 err = ubi_change_vtbl_record(ubi, vol_id, NULL); in ubi_remove_volume()
365 err = ubi_eba_unmap_leb(ubi, vol, i); in ubi_remove_volume()
373 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
374 ubi->rsvd_pebs -= reserved_pebs; in ubi_remove_volume()
375 ubi->avail_pebs += reserved_pebs; in ubi_remove_volume()
376 ubi_update_reserved(ubi); in ubi_remove_volume()
377 ubi->vol_count -= 1; in ubi_remove_volume()
378 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
380 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED); in ubi_remove_volume()
382 self_check_volumes(ubi); in ubi_remove_volume()
387 ubi_err(ubi, "cannot remove volume %d, error %d", vol_id, err); in ubi_remove_volume()
388 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
389 ubi->volumes[vol_id] = vol; in ubi_remove_volume()
391 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
408 struct ubi_device *ubi = vol->ubi; in ubi_resize_volume() local
413 if (ubi->ro_mode) in ubi_resize_volume()
417 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs); in ubi_resize_volume()
421 ubi_err(ubi, "too small size %d, %d LEBs contain data", in ubi_resize_volume()
434 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
436 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
440 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
445 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
446 if (pebs > ubi->avail_pebs) { in ubi_resize_volume()
447 ubi_err(ubi, "not enough PEBs: requested %d, available %d", in ubi_resize_volume()
448 pebs, ubi->avail_pebs); in ubi_resize_volume()
449 if (ubi->corr_peb_count) in ubi_resize_volume()
450 ubi_err(ubi, "%d PEBs are corrupted and not used", in ubi_resize_volume()
451 ubi->corr_peb_count); in ubi_resize_volume()
452 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
456 ubi->avail_pebs -= pebs; in ubi_resize_volume()
457 ubi->rsvd_pebs += pebs; in ubi_resize_volume()
460 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
465 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i); in ubi_resize_volume()
469 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
470 ubi->rsvd_pebs += pebs; in ubi_resize_volume()
471 ubi->avail_pebs -= pebs; in ubi_resize_volume()
472 ubi_update_reserved(ubi); in ubi_resize_volume()
475 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
484 err = ubi_wl_flush(ubi, vol_id, UBI_ALL); in ubi_resize_volume()
490 vtbl_rec = ubi->vtbl[vol_id]; in ubi_resize_volume()
492 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); in ubi_resize_volume()
504 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); in ubi_resize_volume()
505 self_check_volumes(ubi); in ubi_resize_volume()
510 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
511 ubi->rsvd_pebs -= pebs; in ubi_resize_volume()
512 ubi->avail_pebs += pebs; in ubi_resize_volume()
513 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
531 int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list) in ubi_rename_volumes() argument
536 err = ubi_vtbl_rename_volumes(ubi, rename_list); in ubi_rename_volumes()
548 spin_lock(&ubi->volumes_lock); in ubi_rename_volumes()
551 spin_unlock(&ubi->volumes_lock); in ubi_rename_volumes()
552 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED); in ubi_rename_volumes()
557 self_check_volumes(ubi); in ubi_rename_volumes()
570 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_add_volume() argument
580 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1); in ubi_add_volume()
583 ubi_err(ubi, "cannot add character device for volume %d, error %d", in ubi_add_volume()
590 vol->dev.parent = &ubi->dev; in ubi_add_volume()
594 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_add_volume()
602 self_check_volumes(ubi); in ubi_add_volume()
614 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_free_volume() argument
618 ubi->volumes[vol->vol_id] = NULL; in ubi_free_volume()
630 static int self_check_volume(struct ubi_device *ubi, int vol_id) in self_check_volume() argument
632 int idx = vol_id2idx(ubi, vol_id); in self_check_volume()
638 spin_lock(&ubi->volumes_lock); in self_check_volume()
639 reserved_pebs = be32_to_cpu(ubi->vtbl[vol_id].reserved_pebs); in self_check_volume()
640 vol = ubi->volumes[idx]; in self_check_volume()
644 ubi_err(ubi, "no volume info, but volume exists"); in self_check_volume()
647 spin_unlock(&ubi->volumes_lock); in self_check_volume()
653 ubi_err(ubi, "negative values"); in self_check_volume()
656 if (vol->alignment > ubi->leb_size || vol->alignment == 0) { in self_check_volume()
657 ubi_err(ubi, "bad alignment"); in self_check_volume()
661 n = vol->alignment & (ubi->min_io_size - 1); in self_check_volume()
663 ubi_err(ubi, "alignment is not multiple of min I/O unit"); in self_check_volume()
667 n = ubi->leb_size % vol->alignment; in self_check_volume()
669 ubi_err(ubi, "bad data_pad, has to be %lld", n); in self_check_volume()
675 ubi_err(ubi, "bad vol_type"); in self_check_volume()
680 ubi_err(ubi, "update marker and corrupted simultaneously"); in self_check_volume()
684 if (vol->reserved_pebs > ubi->good_peb_count) { in self_check_volume()
685 ubi_err(ubi, "too large reserved_pebs"); in self_check_volume()
689 n = ubi->leb_size - vol->data_pad; in self_check_volume()
690 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) { in self_check_volume()
691 ubi_err(ubi, "bad usable_leb_size, has to be %lld", n); in self_check_volume()
696 ubi_err(ubi, "too long volume name, max is %d", in self_check_volume()
703 ubi_err(ubi, "bad name_len %lld", n); in self_check_volume()
710 ubi_err(ubi, "corrupted dynamic volume"); in self_check_volume()
714 ubi_err(ubi, "bad used_ebs"); in self_check_volume()
718 ubi_err(ubi, "bad last_eb_bytes"); in self_check_volume()
722 ubi_err(ubi, "bad used_bytes"); in self_check_volume()
727 ubi_err(ubi, "bad skip_check"); in self_check_volume()
732 ubi_err(ubi, "bad used_ebs"); in self_check_volume()
737 ubi_err(ubi, "bad last_eb_bytes"); in self_check_volume()
742 ubi_err(ubi, "bad used_bytes"); in self_check_volume()
747 alignment = be32_to_cpu(ubi->vtbl[vol_id].alignment); in self_check_volume()
748 data_pad = be32_to_cpu(ubi->vtbl[vol_id].data_pad); in self_check_volume()
749 name_len = be16_to_cpu(ubi->vtbl[vol_id].name_len); in self_check_volume()
750 upd_marker = ubi->vtbl[vol_id].upd_marker; in self_check_volume()
751 name = &ubi->vtbl[vol_id].name[0]; in self_check_volume()
752 if (ubi->vtbl[vol_id].vol_type == UBI_VID_DYNAMIC) in self_check_volume()
760 ubi_err(ubi, "volume info is different"); in self_check_volume()
764 spin_unlock(&ubi->volumes_lock); in self_check_volume()
768 ubi_err(ubi, "self-check failed for volume %d", vol_id); in self_check_volume()
771 ubi_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id); in self_check_volume()
773 spin_unlock(&ubi->volumes_lock); in self_check_volume()
783 static int self_check_volumes(struct ubi_device *ubi) in self_check_volumes() argument
787 if (!ubi_dbg_chk_gen(ubi)) in self_check_volumes()
790 for (i = 0; i < ubi->vtbl_slots; i++) { in self_check_volumes()
791 err = self_check_volume(ubi, i); in self_check_volumes()