1 diff -u -r linux-2.4.19-rc3.orig/drivers/md/lvm-fs.c linux-2.4.19-rc3/drivers/md/lvm-fs.c
2 --- linux-2.4.19-rc3.orig/drivers/md/lvm-fs.c Thu Jul 25 13:05:13 2002
3 +++ linux-2.4.19-rc3/drivers/md/lvm-fs.c Thu Jul 25 13:46:01 2002
8 - * Copyright (C) 2001 Sistina Software
9 + * Copyright (C) 2001-2002 Sistina Software
11 - * January-April 2001
12 + * January-May,December 2001
15 * LVM driver is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
18 void lvm_fs_create_vg(vg_t *vg_ptr) {
19 struct proc_dir_entry *pde;
24 vg_devfs_handle[vg_ptr->vg_number] =
25 devfs_mk_dir(0, vg_ptr->vg_name, NULL);
28 void lvm_fs_remove_vg(vg_t *vg_ptr) {
34 devfs_unregister(ch_devfs_handle[vg_ptr->vg_number]);
35 ch_devfs_handle[vg_ptr->vg_number] = NULL;
38 - for(i = 0; i < vg_ptr->pv_max; i++)
39 - if(vg_ptr->pv[i]) lvm_fs_remove_pv(vg_ptr, vg_ptr->pv[i]);
42 for(i = 0; i < vg_ptr->lv_max; i++)
43 if(vg_ptr->lv[i]) lvm_fs_remove_lv(vg_ptr, vg_ptr->lv[i]);
46 /* must not remove directory before leaf nodes */
47 devfs_unregister(vg_devfs_handle[vg_ptr->vg_number]);
48 vg_devfs_handle[vg_ptr->vg_number] = NULL;
51 + for(i = 0; i < vg_ptr->pv_max; i++)
52 + if(vg_ptr->pv[i]) lvm_fs_remove_pv(vg_ptr, vg_ptr->pv[i]);
54 if(vg_ptr->vg_dir_pde) {
55 remove_proc_entry(LVM_LV_SUBDIR, vg_ptr->vg_dir_pde);
56 vg_ptr->lv_subdir_pde = NULL;
59 devfs_handle_t lvm_fs_create_lv(vg_t *vg_ptr, lv_t *lv) {
60 struct proc_dir_entry *pde;
61 - const char *name = _basename(lv->lv_name);
67 + name = _basename(lv->lv_name);
69 lv_devfs_handle[MINOR(lv->lv_dev)] = devfs_register(
70 vg_devfs_handle[vg_ptr->vg_number], name,
74 void lvm_fs_remove_lv(vg_t *vg_ptr, lv_t *lv) {
79 devfs_unregister(lv_devfs_handle[MINOR(lv->lv_dev)]);
80 lv_devfs_handle[MINOR(lv->lv_dev)] = NULL;
83 struct proc_dir_entry *pde;
89 if(!vg_ptr->pv_subdir_pde)
93 void lvm_fs_remove_pv(vg_t *vg_ptr, pv_t *pv) {
99 if(!vg_ptr->pv_subdir_pde)
102 diff -u -r linux-2.4.19-rc3.orig/drivers/md/lvm-internal.h linux-2.4.19-rc3/drivers/md/lvm-internal.h
103 --- linux-2.4.19-rc3.orig/drivers/md/lvm-internal.h Thu Jul 25 13:05:13 2002
104 +++ linux-2.4.19-rc3/drivers/md/lvm-internal.h Thu Jul 25 13:46:01 2002
107 extern struct file_operations lvm_chr_fops;
110 +typedef unsigned char uchar;
113 extern struct block_device_operations lvm_blk_dops;
115 #define lvm_sectsize(dev) get_hardsect_size(dev)
116 diff -u -r linux-2.4.19-rc3.orig/drivers/md/lvm-snap.c linux-2.4.19-rc3/drivers/md/lvm-snap.c
117 --- linux-2.4.19-rc3.orig/drivers/md/lvm-snap.c Thu Jul 25 13:05:13 2002
118 +++ linux-2.4.19-rc3/drivers/md/lvm-snap.c Thu Jul 25 13:46:01 2002
122 * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
123 - * 2000 - 2001 Heinz Mauelshagen, Sistina Software
124 + * 2000 - 2002 Heinz Mauelshagen, Sistina Software
126 * LVM snapshot driver is free software; you can redistribute it and/or modify
127 * it under the terms of the GNU General Public License as published by
129 * lvm_snapshot_fill_COW_table has a return value too.
130 * 15/10/2001 - fix snapshot alignment problem [CM]
131 * - fix snapshot full oops (always check lv_block_exception) [CM]
132 + * 26/06/2002 - support for new list_move macro [patch@luckynet.dynu.com]
139 /* fun, isn't it? :) */
141 + list_move(next, hash_table);
144 - list_add(next, hash_table);
145 +#endif list_add(next, hash_table);
149 diff -u -r linux-2.4.19-rc3.orig/drivers/md/lvm.c linux-2.4.19-rc3/drivers/md/lvm.c
150 --- linux-2.4.19-rc3.orig/drivers/md/lvm.c Thu Jul 25 13:05:13 2002
151 +++ linux-2.4.19-rc3/drivers/md/lvm.c Thu Jul 25 13:46:01 2002
156 - * Copyright (C) 1997 - 2001 Heinz Mauelshagen, Sistina Software
157 + * Copyright (C) 1997 - 2002 Heinz Mauelshagen, Sistina Software
159 * February-November 1997
160 * April-May,July-August,November 1998
161 * January-March,May,July,September,October 1999
162 * January,February,July,September-November 2000
163 - * January-April 2001
164 + * January-May,June,October 2001
168 * LVM driver is free software; you can redistribute it and/or modify
170 * in the LV each time. [AED]
171 * 12/10/2001 - Use add/del_gendisk() routines in 2.4.10+
172 * 01/11/2001 - Backport read_ahead change from Linus kernel [AED]
173 + * 24/05/2002 - fixed locking bug in lvm_do_le_remap() introduced with 1.0.4
174 + * 13/06/2002 - use blk_ioctl() to support various standard block ioctls
175 + * - support HDIO_GETGEO_BIG ioctl
176 + * 05/07/2002 - fixed OBO error on vg array access [benh@kernel.crashing.org]
177 + * 22/07/2002 - streamlined blk_ioctl() call
181 @@ -277,14 +283,13 @@
183 * External function prototypes
185 -static int lvm_make_request_fn(request_queue_t *, int,
186 - struct buffer_head *);
187 +static int lvm_make_request_fn(request_queue_t*, int, struct buffer_head*);
189 static int lvm_blk_ioctl(struct inode *, struct file *, uint, ulong);
190 static int lvm_blk_open(struct inode *, struct file *);
192 static int lvm_blk_close(struct inode *, struct file *);
193 -static int lvm_get_snapshot_use_rate(lv_t * lv_ptr, void *arg);
194 +static int lvm_get_snapshot_use_rate(lv_t *lv_ptr, void *arg);
195 static int lvm_user_bmap(struct inode *, struct lv_bmap *);
197 static int lvm_chr_open(struct inode *, struct file *);
198 @@ -314,13 +319,13 @@
199 static int lvm_do_lv_extend_reduce(int, char *, lv_t *);
200 static int lvm_do_lv_remove(int, char *, int);
201 static int lvm_do_lv_rename(vg_t *, lv_req_t *, lv_t *);
202 -static int lvm_do_lv_status_byname(vg_t * r, void *);
203 +static int lvm_do_lv_status_byname(vg_t *r, void *);
204 static int lvm_do_lv_status_byindex(vg_t *, void *);
205 static int lvm_do_lv_status_bydev(vg_t *, void *);
207 -static int lvm_do_pe_lock_unlock(vg_t * r, void *);
208 +static int lvm_do_pe_lock_unlock(vg_t *r, void *);
210 -static int lvm_do_pv_change(vg_t *, void *);
211 +static int lvm_do_pv_change(vg_t*, void*);
212 static int lvm_do_pv_status(vg_t *, void *);
213 static int lvm_do_pv_flush(void *);
215 @@ -330,15 +335,15 @@
216 static int lvm_do_vg_rename(vg_t *, void *);
217 static int lvm_do_vg_remove(int);
218 static void lvm_geninit(struct gendisk *);
219 -static void __update_hardsectsize(lv_t * lv);
220 +static void __update_hardsectsize(lv_t *lv);
223 static void _queue_io(struct buffer_head *bh, int rw);
224 static struct buffer_head *_dequeue_io(void);
225 static void _flush_io(struct buffer_head *bh);
227 -static int _open_pv(pv_t * pv);
228 -static void _close_pv(pv_t * pv);
229 +static int _open_pv(pv_t *pv);
230 +static void _close_pv(pv_t *pv);
232 static unsigned long _sectors_to_k(unsigned long sect);
234 @@ -349,22 +354,20 @@
239 - "LVM version " LVM_RELEASE_NAME "(" LVM_RELEASE_DATE ")";
240 +char *lvm_version = "LVM version "LVM_RELEASE_NAME"("LVM_RELEASE_DATE")";
241 ushort lvm_iop_version = LVM_DRIVER_IOP_VERSION;
243 const char *const lvm_name = LVM_NAME;
246 /* volume group descriptor area pointers */
247 -vg_t *vg[ABS_MAX_VG];
248 +vg_t *vg[ABS_MAX_VG + 1];
250 /* map from block minor number to VG and LV numbers */
256 -static vg_lv_map_t vg_lv_map[ABS_MAX_LV];
257 +} vg_lv_map[ABS_MAX_LV];
260 /* Request structures (lvm_chr_ioctl()) */
261 @@ -394,17 +397,19 @@
264 struct file_operations lvm_chr_fops = {
266 - release:lvm_chr_close,
267 - ioctl:lvm_chr_ioctl,
268 + owner: THIS_MODULE,
269 + open: lvm_chr_open,
270 + release: lvm_chr_close,
271 + ioctl: lvm_chr_ioctl,
274 /* block device operations structure needed for 2.3.38? and above */
275 -struct block_device_operations lvm_blk_dops = {
278 - release:lvm_blk_close,
279 - ioctl:lvm_blk_ioctl,
280 +struct block_device_operations lvm_blk_dops =
282 + owner: THIS_MODULE,
283 + open: lvm_blk_open,
284 + release: lvm_blk_close,
285 + ioctl: lvm_blk_ioctl,
289 @@ -414,14 +419,15 @@
290 static int lvm_hardsectsizes[MAX_LV];
291 static int lvm_size[MAX_LV];
293 -static struct gendisk lvm_gendisk = {
295 - major_name:LVM_NAME,
298 - part:lvm_hd_struct,
301 +static struct gendisk lvm_gendisk =
304 + major_name: LVM_NAME,
307 + part: lvm_hd_struct,
314 lvm_hd_name_ptr = lvm_hd_name;
317 - blk_queue_make_request(BLK_DEFAULT_QUEUE(MAJOR_NR),
318 - lvm_make_request_fn);
319 + blk_queue_make_request(BLK_DEFAULT_QUEUE(MAJOR_NR), lvm_make_request_fn);
322 /* initialise the pe lock */
332 @@ -510,12 +515,11 @@
336 - printk(KERN_INFO "%s -- Module successfully deactivated\n",
338 + printk(KERN_INFO "%s -- Module successfully deactivated\n", lvm_name);
342 -} /* lvm_cleanup() */
343 +} /* lvm_cleanup() */
346 * support function to initialize lvm variables
348 pe_lock_req.data.pv_offset = 0;
350 /* Initialize VG pointers */
351 - for (v = 0; v < ABS_MAX_VG; v++)
352 + for (v = 0; v < ABS_MAX_VG + 1; v++)
355 /* Initialize LV -> VG association */
360 -} /* lvm_init_vars() */
361 +} /* lvm_init_vars() */
364 /********************************************************************
365 @@ -568,15 +572,13 @@
366 minor, VG_CHR(minor), MODE_TO_STR(file->f_mode), lock);
368 /* super user validation */
369 - if (!capable(CAP_SYS_ADMIN))
371 + if (!capable(CAP_SYS_ADMIN)) return -EACCES;
373 /* Group special file open */
374 - if (VG_CHR(minor) > MAX_VG)
376 + if (VG_CHR(minor) > MAX_VG) return -ENXIO;
378 spin_lock(&lvm_lock);
379 - if (lock == current->pid)
380 + if(lock == current->pid)
382 spin_unlock(&lvm_lock);
388 -} /* lvm_chr_open() */
389 +} /* lvm_chr_open() */
393 @@ -602,19 +604,16 @@
394 uint extendable, l, v;
395 void *arg = (void *) a;
397 - vg_t *vg_ptr = vg[VG_CHR(minor)];
398 + vg_t* vg_ptr = vg[VG_CHR(minor)];
400 /* otherwise cc will complain about unused variables */
404 - ("chr MINOR: %d command: 0x%X arg: %p VG#: %d mode: %s%s\n",
405 - minor, command, arg, VG_CHR(minor),
406 - MODE_TO_STR(file->f_mode));
407 + P_IOCTL("chr MINOR: %d command: 0x%X arg: %p VG#: %d mode: %s%s\n",
408 + minor, command, arg, VG_CHR(minor), MODE_TO_STR(file->f_mode));
410 #ifdef LVM_TOTAL_RESET
411 - if (lvm_reset_spindown > 0)
413 + if (lvm_reset_spindown > 0) return -EACCES;
416 /* Main command switch */
418 case LVM_GET_IOP_VERSION:
419 /* check lvm version to ensure driver/tools+lib
421 - if (copy_to_user(arg, &lvm_iop_version, sizeof(ushort)) !=
423 + if (copy_to_user(arg, &lvm_iop_version, sizeof(ushort)) != 0)
427 #ifdef LVM_TOTAL_RESET
429 /* lock reset function */
430 lvm_reset_spindown = 1;
431 for (v = 0; v < ABS_MAX_VG; v++) {
433 - lvm_do_vg_remove(v);
434 + if (vg[v] != NULL) lvm_do_vg_remove(v);
438 @@ -644,28 +642,28 @@
440 while (GET_USE_COUNT(&__this_module) > 1)
444 lock = 0; /* release lock */
445 wake_up_interruptible(&lvm_wait);
447 -#endif /* LVM_TOTAL_RESET */
448 +#endif /* LVM_TOTAL_RESET */
452 /* remap a logical extent (after moving the physical extent) */
453 - return lvm_do_le_remap(vg_ptr, arg);
454 + return lvm_do_le_remap(vg_ptr,arg);
457 /* lock/unlock i/o to a physical extent to move it to another
458 physical volume (move's done in user space's pvmove) */
459 - return lvm_do_pe_lock_unlock(vg_ptr, arg);
460 + return lvm_do_pe_lock_unlock(vg_ptr,arg);
464 return lvm_do_vg_create(arg, minor);
467 - /* create a VGDA, assume VG number is filled in */
468 + /* create a VGDA, assume VG number is filled in */
469 return lvm_do_vg_create(arg, -1);
474 case VG_SET_EXTENDABLE:
475 /* set/clear extendability flag of volume group */
476 - if (vg_ptr == NULL)
478 - if (copy_from_user(&extendable, arg, sizeof(extendable)) !=
480 + if (vg_ptr == NULL) return -ENXIO;
481 + if (copy_from_user(&extendable, arg, sizeof(extendable)) != 0)
484 if (extendable == VG_EXTENDABLE ||
485 extendable == ~VG_EXTENDABLE) {
486 @@ -698,15 +695,13 @@
487 vg_ptr->vg_status |= VG_EXTENDABLE;
489 vg_ptr->vg_status &= ~VG_EXTENDABLE;
492 + } else return -EINVAL;
497 /* get volume group data (only the vg_t struct) */
498 - if (vg_ptr == NULL)
500 + if (vg_ptr == NULL) return -ENXIO;
501 if (copy_to_user(arg, vg_ptr, sizeof(vg_t)) != 0)
504 @@ -739,25 +734,21 @@
507 /* create, extend, reduce, remove or rename a logical volume */
508 - if (vg_ptr == NULL)
510 + if (vg_ptr == NULL) return -ENXIO;
511 if (copy_from_user(&lv_req, arg, sizeof(lv_req)) != 0)
514 if (command != LV_REMOVE) {
515 - if (copy_from_user(&lv, lv_req.lv, sizeof(lv_t)) !=
517 + if (copy_from_user(&lv, lv_req.lv, sizeof(lv_t)) != 0)
522 - return lvm_do_lv_create(minor, lv_req.lv_name,
524 + return lvm_do_lv_create(minor, lv_req.lv_name, &lv);
528 - return lvm_do_lv_extend_reduce(minor,
531 + return lvm_do_lv_extend_reduce(minor, lv_req.lv_name, &lv);
533 return lvm_do_lv_remove(minor, lv_req.lv_name, -1);
535 @@ -785,12 +776,12 @@
538 /* change a physical volume */
539 - return lvm_do_pv_change(vg_ptr, arg);
540 + return lvm_do_pv_change(vg_ptr,arg);
544 /* get physical volume data (pv_t structure only) */
545 - return lvm_do_pv_status(vg_ptr, arg);
546 + return lvm_do_pv_status(vg_ptr,arg);
550 @@ -802,11 +793,11 @@
552 "%s -- lvm_chr_ioctl: unknown command 0x%x\n",
559 -} /* lvm_chr_ioctl */
560 +} /* lvm_chr_ioctl */
564 @@ -824,14 +815,12 @@
568 - if (lvm_chr_open_count > 0)
569 - lvm_chr_open_count--;
570 + if (lvm_chr_open_count > 0) lvm_chr_open_count--;
572 spin_lock(&lvm_lock);
573 - if (lock == current->pid) {
574 - if (!_lock_open_count) {
575 - P_DEV("chr_close: unlocking LVM for pid %d\n",
577 + if(lock == current->pid) {
578 + if(!_lock_open_count) {
579 + P_DEV("chr_close: unlocking LVM for pid %d\n", lock);
581 wake_up_interruptible(&lvm_wait);
587 -} /* lvm_chr_close() */
588 +} /* lvm_chr_close() */
593 vg_t *vg_ptr = vg[VG_BLK(minor)];
595 P_DEV("blk_open MINOR: %d VG#: %d LV#: %d mode: %s%s\n",
596 - minor, VG_BLK(minor), LV_BLK(minor),
597 - MODE_TO_STR(file->f_mode));
598 + minor, VG_BLK(minor), LV_BLK(minor), MODE_TO_STR(file->f_mode));
600 #ifdef LVM_TOTAL_RESET
601 if (lvm_reset_spindown > 0)
602 @@ -873,25 +861,26 @@
603 if (vg_ptr != NULL &&
604 (vg_ptr->vg_status & VG_ACTIVE) &&
605 (lv_ptr = vg_ptr->lv[LV_BLK(minor)]) != NULL &&
606 - LV_BLK(minor) >= 0 && LV_BLK(minor) < vg_ptr->lv_max) {
607 + LV_BLK(minor) >= 0 &&
608 + LV_BLK(minor) < vg_ptr->lv_max) {
610 /* Check parallel LV spindown (LV remove) */
611 - if (lv_ptr->lv_status & LV_SPINDOWN)
613 + if (lv_ptr->lv_status & LV_SPINDOWN) return -EPERM;
615 /* Check inactive LV and open for read/write */
616 /* We need to be able to "read" an inactive LV
617 to re-activate it again */
618 if ((file->f_mode & FMODE_WRITE) &&
619 - (!(lv_ptr->lv_status & LV_ACTIVE))) return -EPERM;
620 + (!(lv_ptr->lv_status & LV_ACTIVE)))
623 if (!(lv_ptr->lv_access & LV_WRITE) &&
624 - (file->f_mode & FMODE_WRITE)) return -EACCES;
625 + (file->f_mode & FMODE_WRITE))
629 - /* be sure to increment VG counter */
630 - if (lv_ptr->lv_open == 0)
632 + /* be sure to increment VG counter */
633 + if (lv_ptr->lv_open == 0) vg_ptr->lv_open++;
637 @@ -901,157 +890,161 @@
641 -} /* lvm_blk_open() */
643 +} /* lvm_blk_open() */
646 - * block device i/o-control routine
648 -static int lvm_blk_ioctl(struct inode *inode, struct file *file,
649 - uint command, ulong a)
650 +/* Deliver "hard disk geometry" */
651 +static int _hdio_getgeo(ulong a, lv_t *lv_ptr, int what)
653 - int minor = MINOR(inode->i_rdev);
654 - vg_t *vg_ptr = vg[VG_BLK(minor)];
655 - lv_t *lv_ptr = vg_ptr->lv[LV_BLK(minor)];
656 - void *arg = (void *) a;
657 - struct hd_geometry *hd = (struct hd_geometry *) a;
659 - P_IOCTL("blk MINOR: %d command: 0x%X arg: %p VG#: %d LV#: %d "
660 - "mode: %s%s\n", minor, command, arg, VG_BLK(minor),
661 - LV_BLK(minor), MODE_TO_STR(file->f_mode));
665 - /* get block device sector size as needed e.g. by fdisk */
666 - return put_user(lvm_sectsize(inode->i_rdev), (int *) arg);
669 - /* return device size */
670 - P_IOCTL("BLKGETSIZE: %u\n", lv_ptr->lv_size);
671 - if (put_user(lv_ptr->lv_size, (unsigned long *) arg))
677 - if (put_user((u64) lv_ptr->lv_size << 9, (u64 *) arg))
683 - /* flush buffer cache */
684 - if (!capable(CAP_SYS_ADMIN))
687 - P_IOCTL("BLKFLSBUF\n");
689 - fsync_dev(inode->i_rdev);
690 - invalidate_buffers(inode->i_rdev);
695 - /* set read ahead for block device */
696 - if (!capable(CAP_SYS_ADMIN))
699 - P_IOCTL("BLKRASET: %ld sectors for %s\n",
700 - (long) arg, kdevname(inode->i_rdev));
702 - if ((long) arg < LVM_MIN_READ_AHEAD ||
703 - (long) arg > LVM_MAX_READ_AHEAD) return -EINVAL;
704 - lv_ptr->lv_read_ahead = (long) arg;
705 - LVM_CORRECT_READ_AHEAD(lv_ptr->lv_read_ahead);
706 - read_ahead[MAJOR_NR] = lv_ptr->lv_read_ahead;
711 + uchar sectors = 128;
715 + while ( heads * sectors > lv_ptr->lv_size) {
719 + cylinders = lv_ptr->lv_size / heads / sectors;
722 - /* get current read ahead setting */
723 - P_IOCTL("BLKRAGET %d\n", lv_ptr->lv_read_ahead);
724 - if (put_user(lv_ptr->lv_read_ahead, (long *) arg))
730 + struct hd_geometry *hd = (struct hd_geometry *) a;
732 + if (put_user(heads, &hd->heads) ||
733 + put_user(sectors, &hd->sectors) ||
734 + put_user((ushort) cylinders, &hd->cylinders) ||
735 + put_user(start, &hd->start))
741 - /* get disk geometry */
742 - P_IOCTL("%s -- lvm_blk_ioctl -- HDIO_GETGEO\n", lvm_name);
745 +#ifdef HDIO_GETGEO_BIG
748 - unsigned char heads = 64;
749 - unsigned char sectors = 32;
752 - lv_ptr->lv_size / heads / sectors;
754 - if (copy_to_user((char *) &hd->heads, &heads,
755 - sizeof(heads)) != 0 ||
756 - copy_to_user((char *) &hd->sectors, §ors,
757 - sizeof(sectors)) != 0 ||
758 - copy_to_user((short *) &hd->cylinders,
760 - sizeof(cylinders)) != 0
761 - || copy_to_user((long *) &hd->start, &start,
762 - sizeof(start)) != 0)
764 + struct hd_big_geometry *hd =
765 + (struct hd_big_geometry *) a;
767 - P_IOCTL("%s -- lvm_blk_ioctl -- cylinders: %d\n",
768 - lvm_name, cylinders);
769 + if (put_user(heads, &hd->heads) ||
770 + put_user(sectors, &hd->sectors) ||
771 + put_user(cylinders, &hd->cylinders) ||
772 + put_user(start, &hd->start))
780 - case LV_SET_ACCESS:
781 - /* set access flags of a logical volume */
782 - if (!capable(CAP_SYS_ADMIN))
784 - lv_ptr->lv_access = (ulong) arg;
785 - if (lv_ptr->lv_access & LV_WRITE)
786 - set_device_ro(lv_ptr->lv_dev, 0);
788 - set_device_ro(lv_ptr->lv_dev, 1);
792 + P_IOCTL("%s -- lvm_blk_ioctl -- cylinders: %d\n",
793 + lvm_name, cylinders);
797 - case LV_SET_STATUS:
798 - /* set status flags of a logical volume */
799 - if (!capable(CAP_SYS_ADMIN))
801 - if (!((ulong) arg & LV_ACTIVE) && lv_ptr->lv_open > 1)
803 - lv_ptr->lv_status = (ulong) arg;
807 - /* turn logical block into (dev_t, block). non privileged. */
808 - /* don't bmap a snapshot, since the mapping can change */
809 - if (lv_ptr->lv_access & LV_SNAPSHOT)
812 - return lvm_user_bmap(inode, (struct lv_bmap *) arg);
814 - case LV_SET_ALLOCATION:
815 - /* set allocation flags of a logical volume */
816 - if (!capable(CAP_SYS_ADMIN))
818 - lv_ptr->lv_allocation = (ulong) arg;
821 + * block device i/o-control routine
823 +static int lvm_blk_ioctl(struct inode *inode, struct file *file,
826 + kdev_t dev = inode->i_rdev;
827 + int minor = MINOR(dev), ret;
828 + vg_t *vg_ptr = vg[VG_BLK(minor)];
829 + lv_t *lv_ptr = vg_ptr->lv[LV_BLK(minor)];
830 + void *arg = (void *) a;
832 - case LV_SNAPSHOT_USE_RATE:
833 - return lvm_get_snapshot_use_rate(lv_ptr, arg);
834 + P_IOCTL("blk MINOR: %d cmd: 0x%X arg: %p VG#: %d LV#: %d "
835 + "mode: %s%s\n", minor, cmd, arg, VG_BLK(minor),
836 + LV_BLK(minor), MODE_TO_STR(file->f_mode));
839 - printk(KERN_WARNING
840 - "%s -- lvm_blk_ioctl: unknown command 0x%x\n",
841 - lvm_name, command);
845 + /* set read ahead for block device */
846 + ret = blk_ioctl(dev, cmd, a);
849 + lv_ptr->lv_read_ahead = (long) a;
850 + LVM_CORRECT_READ_AHEAD(lv_ptr->lv_read_ahead);
854 +#ifdef HDIO_GETGEO_BIG
855 + case HDIO_GETGEO_BIG:
857 + /* get disk geometry */
858 + P_IOCTL("%s -- lvm_blk_ioctl -- HDIO_GETGEO\n",
865 + return _hdio_getgeo(a, lv_ptr, 0);
866 +#ifdef HDIO_GETGEO_BIG
867 + case HDIO_GETGEO_BIG:
868 + return _hdio_getgeo(a, lv_ptr, 1);
873 + /* turn logical block into (dev_t, block). non privileged. */
874 + /* don't bmap a snapshot, since the mapping can change */
875 + if (lv_ptr->lv_access & LV_SNAPSHOT)
878 + return lvm_user_bmap(inode, (struct lv_bmap *) arg);
880 + case LV_SET_ACCESS:
881 + /* set access flags of a logical volume */
882 + if (!capable(CAP_SYS_ADMIN)) return -EACCES;
884 + down_write(&lv_ptr->lv_lock);
885 + lv_ptr->lv_access = (ulong) arg;
886 + up_write(&lv_ptr->lv_lock);
888 + if ( lv_ptr->lv_access & LV_WRITE)
889 + set_device_ro(lv_ptr->lv_dev, 0);
891 + set_device_ro(lv_ptr->lv_dev, 1);
895 + case LV_SET_ALLOCATION:
896 + /* set allocation flags of a logical volume */
897 + if (!capable(CAP_SYS_ADMIN)) return -EACCES;
898 + down_write(&lv_ptr->lv_lock);
899 + lv_ptr->lv_allocation = (ulong) arg;
900 + up_write(&lv_ptr->lv_lock);
903 + case LV_SET_STATUS:
904 + /* set status flags of a logical volume */
905 + if (!capable(CAP_SYS_ADMIN)) return -EACCES;
906 + if (!((ulong) arg & LV_ACTIVE) && lv_ptr->lv_open > 1)
908 + down_write(&lv_ptr->lv_lock);
909 + lv_ptr->lv_status = (ulong) arg;
910 + up_write(&lv_ptr->lv_lock);
913 + case LV_SNAPSHOT_USE_RATE:
914 + return lvm_get_snapshot_use_rate(lv_ptr, arg);
917 + /* Handle rest here */
918 + ret = blk_ioctl(dev, cmd, a);
920 + printk(KERN_WARNING
921 + "%s -- lvm_blk_ioctl: unknown "
928 -} /* lvm_blk_ioctl() */
929 +} /* lvm_blk_ioctl() */
933 @@ -1066,21 +1059,24 @@
934 P_DEV("blk_close MINOR: %d VG#: %d LV#: %d\n",
935 minor, VG_BLK(minor), LV_BLK(minor));
937 - if (lv_ptr->lv_open == 1)
939 + if (lv_ptr->lv_open == 1) vg_ptr->lv_open--;
945 -} /* lvm_blk_close() */
946 +} /* lvm_blk_close() */
948 -static int lvm_get_snapshot_use_rate(lv_t * lv, void *arg)
949 +static int lvm_get_snapshot_use_rate(lv_t *lv, void *arg)
951 lv_snapshot_use_rate_req_t lv_rate_req;
953 - if (!(lv->lv_access & LV_SNAPSHOT))
954 + down_read(&lv->lv_lock);
955 + if (!(lv->lv_access & LV_SNAPSHOT)) {
956 + up_read(&lv->lv_lock);
959 + up_read(&lv->lv_lock);
961 if (copy_from_user(&lv_rate_req, arg, sizeof(lv_rate_req)))
963 @@ -1090,10 +1086,17 @@
965 switch (lv_rate_req.block) {
967 + down_write(&lv->lv_lock);
968 lv->lv_snapshot_use_rate = lv_rate_req.rate;
969 + up_write(&lv->lv_lock);
970 + down_read(&lv->lv_lock);
971 if (lv->lv_remap_ptr * 100 / lv->lv_remap_end <
972 - lv->lv_snapshot_use_rate)
973 - interruptible_sleep_on(&lv->lv_snapshot_wait);
974 + lv->lv_snapshot_use_rate) {
975 + up_read(&lv->lv_lock);
976 + interruptible_sleep_on(&lv->lv_snapshot_wait);
977 + down_read(&lv->lv_lock);
979 + up_read(&lv->lv_lock);
983 @@ -1102,7 +1105,9 @@
987 + down_read(&lv->lv_lock);
988 lv_rate_req.rate = lv->lv_remap_ptr * 100 / lv->lv_remap_end;
989 + up_read(&lv->lv_lock);
991 return copy_to_user(arg, &lv_rate_req,
992 sizeof(lv_rate_req)) ? -EFAULT : 0;
993 @@ -1117,20 +1122,20 @@
994 if (get_user(block, &user_result->lv_block))
997 - memset(&bh, 0, sizeof bh);
998 + memset(&bh,0,sizeof bh);
999 bh.b_blocknr = block;
1000 bh.b_dev = bh.b_rdev = inode->i_rdev;
1001 bh.b_size = lvm_get_blksize(bh.b_dev);
1002 bh.b_rsector = block * (bh.b_size >> 9);
1004 - if ((err = lvm_map(&bh, READ)) < 0) {
1005 + if ((err = lvm_map(&bh, READ)) < 0) {
1006 printk("lvm map failed: %d\n", err);
1010 return put_user(kdev_t_to_nr(bh.b_rdev), &user_result->lv_dev) ||
1011 - put_user(bh.b_rsector / (bh.b_size >> 9),
1012 - &user_result->lv_block) ? -EFAULT : 0;
1013 + put_user(bh.b_rsector/(bh.b_size>>9), &user_result->lv_block) ?
1018 @@ -1139,8 +1144,7 @@
1019 * (see init_module/lvm_init)
1021 static void __remap_snapshot(kdev_t rdev, ulong rsector,
1022 - ulong pe_start, lv_t * lv, vg_t * vg)
1024 + ulong pe_start, lv_t *lv, vg_t *vg) {
1026 /* copy a chunk from the origin to a snapshot device */
1027 down_write(&lv->lv_lock);
1028 @@ -1155,8 +1159,7 @@
1031 static inline void _remap_snapshot(kdev_t rdev, ulong rsector,
1032 - ulong pe_start, lv_t * lv, vg_t * vg)
1034 + ulong pe_start, lv_t *lv, vg_t *vg) {
1037 /* check to see if this chunk is already in the snapshot */
1038 @@ -1173,8 +1176,7 @@
1040 * extents destined for a pe that is on the move should be deferred
1042 -static inline int _should_defer(kdev_t pv, ulong sector, uint32_t pe_size)
1044 +static inline int _should_defer(kdev_t pv, ulong sector, uint32_t pe_size) {
1045 return ((pe_lock_req.lock == LOCK_PE) &&
1046 (pv == pe_lock_req.data.pv_dev) &&
1047 (sector >= pe_lock_req.data.pv_offset) &&
1048 @@ -1221,32 +1223,34 @@
1052 - if ((rw == WRITE || rw == WRITEA) && !(lv->lv_access & LV_WRITE)) {
1053 + if ((rw == WRITE || rw == WRITEA) &&
1054 + !(lv->lv_access & LV_WRITE)) {
1056 "%s - lvm_map: ll_rw_blk write for readonly LV %s\n",
1057 lvm_name, lv->lv_name);
1062 - ("%s - lvm_map minor: %d *rdev: %s *rsector: %lu size:%lu\n",
1063 - lvm_name, minor, kdevname(bh->b_rdev), rsector_org, size);
1064 + P_MAP("%s - lvm_map minor: %d *rdev: %s *rsector: %lu size:%lu\n",
1066 + kdevname(bh->b_rdev),
1067 + rsector_org, size);
1069 if (rsector_org + size > lv->lv_size) {
1071 "%s - lvm_map access beyond end of device; *rsector: "
1072 - "%lu or size: %lu wrong for minor: %2d\n",
1073 - lvm_name, rsector_org, size, minor);
1074 + "%lu or size: %lu wrong for minor: %2d\n",
1075 + lvm_name, rsector_org, size, minor);
1080 - if (lv->lv_stripes < 2) { /* linear mapping */
1081 + if (lv->lv_stripes < 2) { /* linear mapping */
1083 index = rsector_org / vg_this->pe_size;
1084 pe_start = lv->lv_current_pe[index].pe;
1085 rsector_map = lv->lv_current_pe[index].pe +
1086 - (rsector_org % vg_this->pe_size);
1087 + (rsector_org % vg_this->pe_size);
1088 rdev_map = lv->lv_current_pe[index].dev;
1090 P_MAP("lv_current_pe[%ld].pe: %d rdev: %s rsector:%ld\n",
1091 @@ -1259,23 +1263,22 @@
1093 stripe_length = vg_this->pe_size * lv->lv_stripes;
1094 stripe_index = (rsector_org % stripe_length) /
1095 - lv->lv_stripesize;
1096 + lv->lv_stripesize;
1097 index = rsector_org / stripe_length +
1098 - (stripe_index % lv->lv_stripes) *
1099 - (lv->lv_allocated_le / lv->lv_stripes);
1100 + (stripe_index % lv->lv_stripes) *
1101 + (lv->lv_allocated_le / lv->lv_stripes);
1102 pe_start = lv->lv_current_pe[index].pe;
1103 rsector_map = lv->lv_current_pe[index].pe +
1104 - (rsector_org % stripe_length) -
1105 - (stripe_index % lv->lv_stripes) * lv->lv_stripesize -
1106 - stripe_index / lv->lv_stripes *
1107 - (lv->lv_stripes - 1) * lv->lv_stripesize;
1108 + (rsector_org % stripe_length) -
1109 + (stripe_index % lv->lv_stripes) * lv->lv_stripesize -
1110 + stripe_index / lv->lv_stripes *
1111 + (lv->lv_stripes - 1) * lv->lv_stripesize;
1112 rdev_map = lv->lv_current_pe[index].dev;
1114 P_MAP("lv_current_pe[%ld].pe: %d rdev: %s rsector:%ld\n"
1115 "stripe_length: %ld stripe_index: %ld\n",
1116 - index, lv->lv_current_pe[index].pe,
1117 - kdevname(rdev_map), rsector_map, stripe_length,
1119 + index, lv->lv_current_pe[index].pe, kdevname(rdev_map),
1120 + rsector_map, stripe_length, stripe_index);
1124 @@ -1284,8 +1287,8 @@
1125 * we need to queue this request, because this is in the fast path.
1127 if (rw == WRITE || rw == WRITEA) {
1128 - if (_defer_extent(bh, rw, rdev_map,
1129 - rsector_map, vg_this->pe_size)) {
1130 + if(_defer_extent(bh, rw, rdev_map,
1131 + rsector_map, vg_this->pe_size)) {
1133 up_read(&lv->lv_lock);
1135 @@ -1296,14 +1299,15 @@
1136 lv->lv_current_pe[index].reads++; /* statistic */
1138 /* snapshot volume exception handling on physical device address base */
1139 - if (!(lv->lv_access & (LV_SNAPSHOT | LV_SNAPSHOT_ORG)))
1140 + if (!(lv->lv_access & (LV_SNAPSHOT|LV_SNAPSHOT_ORG)))
1143 - if (lv->lv_access & LV_SNAPSHOT) { /* remap snapshot */
1144 - if (lvm_snapshot_remap_block
1145 - (&rdev_map, &rsector_map, pe_start, lv) < 0)
1147 - } else if (rw == WRITE || rw == WRITEA) { /* snapshot origin */
1148 + if (lv->lv_access & LV_SNAPSHOT) { /* remap snapshot */
1149 + if (lvm_snapshot_remap_block(&rdev_map, &rsector_map,
1150 + pe_start, lv) < 0)
1153 + } else if (rw == WRITE || rw == WRITEA) { /* snapshot origin */
1156 /* start with first snapshot and loop through all of
1157 @@ -1317,21 +1321,22 @@
1158 /* Serializes the COW with the accesses to the
1160 _remap_snapshot(rdev_map, rsector_map,
1161 - pe_start, snap, vg_this);
1162 + pe_start, snap, vg_this);
1168 bh->b_rdev = rdev_map;
1169 bh->b_rsector = rsector_map;
1170 up_read(&lv->lv_lock);
1174 - if (bh->b_end_io) buffer_IO_error(bh);
1177 + buffer_IO_error(bh);
1178 up_read(&lv->lv_lock);
1185 @@ -1363,8 +1368,9 @@
1187 * make request function
1189 -static int lvm_make_request_fn(request_queue_t * q,
1190 - int rw, struct buffer_head *bh)
1191 +static int lvm_make_request_fn(request_queue_t *q,
1193 + struct buffer_head *bh)
1195 return (lvm_map(bh, rw) <= 0) ? 0 : 1;
1197 @@ -1380,7 +1386,7 @@
1199 static int lvm_do_lock_lvm(void)
1203 spin_lock(&lvm_lock);
1204 if (lock != 0 && lock != current->pid) {
1205 P_DEV("lvm_do_lock_lvm: locked by pid %d ...\n", lock);
1206 @@ -1398,20 +1404,19 @@
1207 P_DEV("lvm_do_lock_lvm: locking LVM for pid %d\n", lock);
1208 spin_unlock(&lvm_lock);
1210 -} /* lvm_do_lock_lvm */
1211 +} /* lvm_do_lock_lvm */
1215 * character device support function lock/unlock physical extend
1217 -static int lvm_do_pe_lock_unlock(vg_t * vg_ptr, void *arg)
1218 +static int lvm_do_pe_lock_unlock(vg_t *vg_ptr, void *arg)
1220 pe_lock_req_t new_lock;
1221 struct buffer_head *bh;
1224 - if (vg_ptr == NULL)
1226 + if (vg_ptr == NULL) return -ENXIO;
1227 if (copy_from_user(&new_lock, arg, sizeof(new_lock)) != 0)
1230 @@ -1422,8 +1427,7 @@
1231 new_lock.data.pv_dev == vg_ptr->pv[p]->pv_dev)
1234 - if (p == vg_ptr->pv_max)
1236 + if (p == vg_ptr->pv_max) return -ENXIO;
1239 * this sync releaves memory pressure to lessen the
1240 @@ -1474,20 +1478,24 @@
1242 * character device support function logical extend remap
1244 -static int lvm_do_le_remap(vg_t * vg_ptr, void *arg)
1245 +static int lvm_do_le_remap(vg_t *vg_ptr, void *arg)
1250 - if (vg_ptr == NULL)
1252 + if (vg_ptr == NULL) return -ENXIO;
1253 if (copy_from_user(&le_remap_req, arg,
1254 - sizeof(le_remap_req_t)) != 0) return -EFAULT;
1255 + sizeof(le_remap_req_t)) != 0)
1258 for (l = 0; l < vg_ptr->lv_max; l++) {
1259 lv_ptr = vg_ptr->lv[l];
1260 - if (lv_ptr != NULL &&
1261 - strcmp(lv_ptr->lv_name, le_remap_req.lv_name) == 0) {
1266 + if (strcmp(lv_ptr->lv_name, le_remap_req.lv_name) == 0) {
1267 + down_write(&lv_ptr->lv_lock);
1268 for (le = 0; le < lv_ptr->lv_allocated_le; le++) {
1269 if (lv_ptr->lv_current_pe[le].dev ==
1270 le_remap_req.old_dev &&
1271 @@ -1497,16 +1505,17 @@
1272 le_remap_req.new_dev;
1273 lv_ptr->lv_current_pe[le].pe =
1274 le_remap_req.new_pe;
1276 __update_hardsectsize(lv_ptr);
1277 + up_write(&lv_ptr->lv_lock);
1281 + up_write(&lv_ptr->lv_lock);
1286 -} /* lvm_do_le_remap() */
1287 +} /* lvm_do_le_remap() */
1291 @@ -1520,7 +1529,7 @@
1295 - if ((vg_ptr = kmalloc(sizeof(vg_t), GFP_KERNEL)) == NULL) {
1296 + if ((vg_ptr = kmalloc(sizeof(vg_t),GFP_KERNEL)) == NULL) {
1298 "%s -- VG_CREATE: kmalloc error VG at line %d\n",
1299 lvm_name, __LINE__);
1300 @@ -1528,9 +1537,8 @@
1302 /* get the volume group structure */
1303 if (copy_from_user(vg_ptr, arg, sizeof(vg_t)) != 0) {
1305 - ("lvm_do_vg_create ERROR: copy VG ptr %p (%d bytes)\n",
1306 - arg, sizeof(vg_t));
1307 + P_IOCTL("lvm_do_vg_create ERROR: copy VG ptr %p (%d bytes)\n",
1308 + arg, sizeof(vg_t));
1312 @@ -1539,6 +1547,10 @@
1314 minor = vg_ptr->vg_number;
1316 + /* check limits */
1317 + if (minor >= ABS_MAX_VG)
1321 if (vg[VG_CHR(minor)] != NULL) {
1322 P_IOCTL("lvm_do_vg_create ERROR: VG %d in use\n", minor);
1323 @@ -1560,7 +1572,7 @@
1325 if (vg_ptr->lv_max > ABS_MAX_LV) {
1327 - "%s -- Can't activate VG: ABS_MAX_LV too small for %u\n",
1328 + "%s -- Can't activate VG: ABS_MAX_LV too small for %u\n",
1329 lvm_name, vg_ptr->lv_max);
1332 @@ -1578,7 +1590,7 @@
1333 /* user space address */
1334 if ((pvp = vg_ptr->pv[p]) != NULL) {
1335 ret = lvm_do_pv_create(pvp, vg_ptr, p);
1338 lvm_do_vg_remove(minor);
1341 @@ -1586,7 +1598,7 @@
1344 size = vg_ptr->lv_max * sizeof(lv_t *);
1345 - if ((snap_lv_ptr = vmalloc(size)) == NULL) {
1346 + if ((snap_lv_ptr = vmalloc ( size)) == NULL) {
1348 "%s -- VG_CREATE: vmalloc error snapshot LVs at line %d\n",
1349 lvm_name, __LINE__);
1350 @@ -1602,13 +1614,12 @@
1351 /* user space address */
1352 if ((lvp = vg_ptr->lv[l]) != NULL) {
1353 if (copy_from_user(&lv, lvp, sizeof(lv_t)) != 0) {
1355 - ("ERROR: copying LV ptr %p (%d bytes)\n",
1356 - lvp, sizeof(lv_t));
1357 + P_IOCTL("ERROR: copying LV ptr %p (%d bytes)\n",
1358 + lvp, sizeof(lv_t));
1359 lvm_do_vg_remove(minor);
1362 - if (lv.lv_access & LV_SNAPSHOT) {
1363 + if ( lv.lv_access & LV_SNAPSHOT) {
1364 snap_lv_ptr[ls] = lvp;
1365 vg_ptr->lv[l] = NULL;
1367 @@ -1648,26 +1659,24 @@
1368 vg_ptr->vg_status |= VG_ACTIVE;
1371 -} /* lvm_do_vg_create() */
1372 +} /* lvm_do_vg_create() */
1376 * character device support function VGDA extend
1378 -static int lvm_do_vg_extend(vg_t * vg_ptr, void *arg)
1379 +static int lvm_do_vg_extend(vg_t *vg_ptr, void *arg)
1385 - if (vg_ptr == NULL)
1387 + if (vg_ptr == NULL) return -ENXIO;
1388 if (vg_ptr->pv_cur < vg_ptr->pv_max) {
1389 for (p = 0; p < vg_ptr->pv_max; p++) {
1390 - if ((pv_ptr = vg_ptr->pv[p]) == NULL) {
1391 + if ( ( pv_ptr = vg_ptr->pv[p]) == NULL) {
1392 ret = lvm_do_pv_create(arg, vg_ptr, p);
1395 + if ( ret != 0) return ret;
1396 pv_ptr = vg_ptr->pv[p];
1397 vg_ptr->pe_total += pv_ptr->pe_total;
1399 @@ -1675,28 +1684,26 @@
1403 -} /* lvm_do_vg_extend() */
1404 +} /* lvm_do_vg_extend() */
1408 * character device support function VGDA reduce
1410 -static int lvm_do_vg_reduce(vg_t * vg_ptr, void *arg)
1412 +static int lvm_do_vg_reduce(vg_t *vg_ptr, void *arg) {
1416 - if (vg_ptr == NULL)
1418 + if (vg_ptr == NULL) return -ENXIO;
1419 if (copy_from_user(pv_name, arg, sizeof(pv_name)) != 0)
1422 for (p = 0; p < vg_ptr->pv_max; p++) {
1423 pv_ptr = vg_ptr->pv[p];
1424 if (pv_ptr != NULL &&
1425 - strcmp(pv_ptr->pv_name, pv_name) == 0) {
1426 - if (pv_ptr->lv_cur > 0)
1428 + strcmp(pv_ptr->pv_name,
1430 + if (pv_ptr->lv_cur > 0) return -EPERM;
1431 lvm_do_pv_remove(vg_ptr, p);
1432 /* Make PV pointer array contiguous */
1433 for (; p < vg_ptr->pv_max - 1; p++)
1434 @@ -1706,55 +1713,74 @@
1438 -} /* lvm_do_vg_reduce */
1439 +} /* lvm_do_vg_reduce */
1443 * character device support function VG rename
1445 -static int lvm_do_vg_rename(vg_t * vg_ptr, void *arg)
1446 +static int lvm_do_vg_rename(vg_t *vg_ptr, void *arg)
1448 int l = 0, p = 0, len = 0;
1449 - char vg_name[NAME_LEN] = { 0, };
1450 - char lv_name[NAME_LEN] = { 0, };
1451 + char vg_name[NAME_LEN] = { 0,};
1452 + char lv_name[NAME_LEN] = { 0,};
1454 lv_t *lv_ptr = NULL;
1455 pv_t *pv_ptr = NULL;
1457 /* If the VG doesn't exist in the kernel then just exit */
1460 + if (!vg_ptr) return 0;
1462 if (copy_from_user(vg_name, arg, sizeof(vg_name)) != 0)
1465 lvm_fs_remove_vg(vg_ptr);
1467 - strncpy(vg_ptr->vg_name, vg_name, sizeof(vg_name) - 1);
1468 - for (l = 0; l < vg_ptr->lv_max; l++) {
1469 - if ((lv_ptr = vg_ptr->lv[l]) == NULL)
1471 - strncpy(lv_ptr->vg_name, vg_name, sizeof(vg_name));
1472 + strncpy ( vg_ptr->vg_name, vg_name, sizeof ( vg_name)-1);
1473 + for ( l = 0; l < vg_ptr->lv_max; l++)
1475 + if ((lv_ptr = vg_ptr->lv[l]) == NULL) continue;
1476 + memset (lv_ptr->vg_name, 0, sizeof (*vg_name));
1477 + strncpy(lv_ptr->vg_name, vg_name, sizeof ( vg_name));
1478 ptr = strrchr(lv_ptr->lv_name, '/');
1480 - ptr = lv_ptr->lv_name;
1481 - strncpy(lv_name, ptr, sizeof(lv_name));
1482 + ptr = ptr ? ptr + 1 : lv_ptr->lv_name;
1483 + strncpy(lv_name, ptr, sizeof ( lv_name));
1484 len = sizeof(LVM_DIR_PREFIX);
1485 strcpy(lv_ptr->lv_name, LVM_DIR_PREFIX);
1486 strncat(lv_ptr->lv_name, vg_name, NAME_LEN - len);
1487 - len += strlen(vg_name);
1488 + strcat (lv_ptr->lv_name, "/");
1489 + len += strlen(vg_name) + 1;
1490 strncat(lv_ptr->lv_name, lv_name, NAME_LEN - len);
1492 - for (p = 0; p < vg_ptr->pv_max; p++) {
1493 - if ((pv_ptr = vg_ptr->pv[p]) == NULL)
1495 + for ( p = 0; p < vg_ptr->pv_max; p++)
1497 + if ( (pv_ptr = vg_ptr->pv[p]) == NULL) continue;
1498 strncpy(pv_ptr->vg_name, vg_name, NAME_LEN);
1501 lvm_fs_create_vg(vg_ptr);
1503 + /* Need to add PV entries */
1504 + for ( p = 0; p < vg_ptr->pv_act; p++) {
1505 + pv_t *pv_ptr = vg_ptr->pv[p];
1508 + lvm_fs_create_pv(vg_ptr, pv_ptr);
1511 + /* Need to add LV entries */
1512 + for ( l = 0; l < vg_ptr->lv_max; l++) {
1513 + lv_t *lv_ptr = vg_ptr->lv[l];
1518 + lvm_gendisk.part[MINOR(lv_ptr->lv_dev)].de =
1519 + lvm_fs_create_lv(vg_ptr, lv_ptr);
1523 -} /* lvm_do_vg_rename */
1524 +} /* lvm_do_vg_rename */
1528 @@ -1766,8 +1792,7 @@
1529 vg_t *vg_ptr = vg[VG_CHR(minor)];
1532 - if (vg_ptr == NULL)
1534 + if (vg_ptr == NULL) return -ENXIO;
1536 #ifdef LVM_TOTAL_RESET
1537 if (vg_ptr->lv_open > 0 && lvm_reset_spindown == 0)
1538 @@ -1818,18 +1843,20 @@
1542 -} /* lvm_do_vg_remove() */
1543 +} /* lvm_do_vg_remove() */
1547 * character device support function physical volume create
1549 -static int lvm_do_pv_create(pv_t * pvp, vg_t * vg_ptr, ulong p)
1551 +static int lvm_do_pv_create(pv_t *pvp, vg_t *vg_ptr, ulong p) {
1555 - pv = kmalloc(sizeof(pv_t), GFP_KERNEL);
1559 + pv = kmalloc(sizeof(pv_t),GFP_KERNEL);
1562 "%s -- PV_CREATE: kmalloc error PV at line %d\n",
1563 @@ -1840,9 +1867,8 @@
1564 memset(pv, 0, sizeof(*pv));
1566 if (copy_from_user(pv, pvp, sizeof(pv_t)) != 0) {
1568 - ("lvm_do_pv_create ERROR: copy PV ptr %p (%d bytes)\n",
1569 - pvp, sizeof(pv_t));
1570 + P_IOCTL("lvm_do_pv_create ERROR: copy PV ptr %p (%d bytes)\n",
1571 + pvp, sizeof(pv_t));
1575 @@ -1863,14 +1889,13 @@
1579 -} /* lvm_do_pv_create() */
1580 +} /* lvm_do_pv_create() */
1584 * character device support function physical volume remove
1586 -static int lvm_do_pv_remove(vg_t * vg_ptr, ulong p)
1588 +static int lvm_do_pv_remove(vg_t *vg_ptr, ulong p) {
1589 pv_t *pv = vg_ptr->pv[p];
1591 lvm_fs_remove_pv(vg_ptr, pv);
1592 @@ -1888,7 +1913,7 @@
1596 -static void __update_hardsectsize(lv_t * lv)
1597 +static void __update_hardsectsize(lv_t *lv)
1599 int max_hardsectsize = 0, hardsectsize = 0;
1601 @@ -1900,10 +1925,9 @@
1602 if (max_hardsectsize == 0)
1603 max_hardsectsize = hardsectsize;
1604 else if (hardsectsize != max_hardsectsize) {
1606 - ("%s PV[%d] (%s) sector size %d, not %d\n",
1607 - lv->lv_name, p, kdevname(pv->pv_dev),
1608 - hardsectsize, max_hardsectsize);
1609 + P_DEV("%s PV[%d] (%s) sector size %d, not %d\n",
1610 + lv->lv_name, p, kdevname(pv->pv_dev),
1611 + hardsectsize, max_hardsectsize);
1615 @@ -1913,14 +1937,12 @@
1616 if (hardsectsize != max_hardsectsize) {
1618 for (le = 0; le < lv->lv_allocated_le; le++) {
1620 - lvm_sectsize(lv->lv_current_pe[le].dev);
1621 + hardsectsize = lvm_sectsize(lv->lv_current_pe[le].dev);
1622 if (hardsectsize > max_hardsectsize) {
1624 - ("%s LE[%d] (%s) blocksize %d not %d\n",
1626 - kdevname(lv->lv_current_pe[le].dev),
1627 - hardsectsize, max_hardsectsize);
1628 + P_DEV("%s LE[%d] (%s) blocksize %d not %d\n",
1630 + kdevname(lv->lv_current_pe[le].dev),
1631 + hardsectsize, max_hardsectsize);
1632 max_hardsectsize = hardsectsize;
1635 @@ -1930,9 +1952,7 @@
1636 (lv->lv_status & LV_ACTIVE)) {
1638 for (e = 0; e < lv->lv_remap_end; e++) {
1640 - lvm_sectsize(lv->lv_block_exception[e].
1642 + hardsectsize = lvm_sectsize(lv->lv_block_exception[e].rdev_new);
1643 if (hardsectsize > max_hardsectsize)
1644 max_hardsectsize = hardsectsize;
1646 @@ -1949,7 +1969,7 @@
1648 * character device support function logical volume create
1650 -static int lvm_do_lv_create(int minor, char *lv_name, lv_t * lv)
1651 +static int lvm_do_lv_create(int minor, char *lv_name, lv_t *lv)
1653 int e, ret, l, le, l_new, p, size, activate = 1;
1654 ulong lv_status_save;
1655 @@ -1977,18 +1997,14 @@
1657 for (l = 0; l < vg_ptr->lv_max; l++) {
1658 if (vg_ptr->lv[l] == NULL)
1661 + if (l_new == -1) l_new = l;
1668 + if (l_new == -1) return -EPERM;
1671 - if ((lv_ptr = kmalloc(sizeof(lv_t), GFP_KERNEL)) == NULL) {;
1673 - "%s -- LV_CREATE: kmalloc error LV at line %d\n",
1674 + if ((lv_ptr = kmalloc(sizeof(lv_t),GFP_KERNEL)) == NULL) {;
1675 + printk(KERN_CRIT "%s -- LV_CREATE: kmalloc error LV at line %d\n",
1676 lvm_name, __LINE__);
1679 @@ -2020,7 +2036,8 @@
1680 if ((lv_ptr->lv_current_pe = vmalloc(size)) == NULL) {
1682 "%s -- LV_CREATE: vmalloc error LV_CURRENT_PE of %d Byte "
1683 - "at line %d\n", lvm_name, size, __LINE__);
1685 + lvm_name, size, __LINE__);
1686 P_KFREE("%s -- kfree %d\n", lvm_name, __LINE__);
1688 vg_ptr->lv[l] = NULL;
1689 @@ -2049,9 +2066,7 @@
1690 lv_ptr->lv_snapshot_org =
1691 vg_ptr->lv[LV_BLK(lv_ptr->lv_snapshot_minor)];
1692 if (lv_ptr->lv_snapshot_org != NULL) {
1694 - lv_ptr->lv_remap_end *
1695 - sizeof(lv_block_exception_t);
1696 + size = lv_ptr->lv_remap_end * sizeof(lv_block_exception_t);
1700 @@ -2061,33 +2076,29 @@
1705 - (lv_ptr->lv_block_exception =
1706 - vmalloc(size)) == NULL) {
1707 + if ((lv_ptr->lv_block_exception = vmalloc(size)) == NULL) {
1709 "%s -- lvm_do_lv_create: vmalloc error LV_BLOCK_EXCEPTION "
1710 "of %d byte at line %d\n",
1711 lvm_name, size, __LINE__);
1712 - P_KFREE("%s -- kfree %d\n",
1713 - lvm_name, __LINE__);
1714 + P_KFREE("%s -- kfree %d\n", lvm_name,
1717 vg_ptr->lv[l] = NULL;
1720 - if (copy_from_user
1721 - (lv_ptr->lv_block_exception, lvbe,
1723 + if (copy_from_user(lv_ptr->lv_block_exception, lvbe, size)) {
1724 vfree(lv_ptr->lv_block_exception);
1726 vg_ptr->lv[l] = NULL;
1730 - if (lv_ptr->lv_block_exception[0].
1732 - LVM_SNAPSHOT_DROPPED_SECTOR) {
1733 + if(lv_ptr->lv_block_exception[0].rsector_org ==
1734 + LVM_SNAPSHOT_DROPPED_SECTOR)
1737 - "%s -- lvm_do_lv_create: snapshot has been dropped and will not be activated\n",
1738 + "%s -- lvm_do_lv_create: snapshot has been dropped and will not be activated\n",
1742 @@ -2101,54 +2112,36 @@
1743 which can be the original logical volume */
1744 lv_ptr = vg_ptr->lv[l];
1745 /* now lv_ptr points to our new last snapshot logical volume */
1746 - lv_ptr->lv_current_pe =
1747 - lv_ptr->lv_snapshot_org->lv_current_pe;
1748 - lv_ptr->lv_allocated_snapshot_le =
1749 - lv_ptr->lv_allocated_le;
1750 - lv_ptr->lv_allocated_le =
1751 - lv_ptr->lv_snapshot_org->
1753 - lv_ptr->lv_current_le =
1754 - lv_ptr->lv_snapshot_org->lv_current_le;
1756 - lv_ptr->lv_snapshot_org->lv_size;
1757 - lv_ptr->lv_stripes =
1758 - lv_ptr->lv_snapshot_org->lv_stripes;
1759 - lv_ptr->lv_stripesize =
1760 - lv_ptr->lv_snapshot_org->lv_stripesize;
1761 + lv_ptr->lv_current_pe = lv_ptr->lv_snapshot_org->lv_current_pe;
1762 + lv_ptr->lv_allocated_snapshot_le = lv_ptr->lv_allocated_le;
1763 + lv_ptr->lv_allocated_le = lv_ptr->lv_snapshot_org->lv_allocated_le;
1764 + lv_ptr->lv_current_le = lv_ptr->lv_snapshot_org->lv_current_le;
1765 + lv_ptr->lv_size = lv_ptr->lv_snapshot_org->lv_size;
1766 + lv_ptr->lv_stripes = lv_ptr->lv_snapshot_org->lv_stripes;
1767 + lv_ptr->lv_stripesize = lv_ptr->lv_snapshot_org->lv_stripesize;
1769 /* Update the VG PE(s) used by snapshot reserve space. */
1770 - vg_ptr->pe_allocated +=
1771 - lv_ptr->lv_allocated_snapshot_le;
1772 + vg_ptr->pe_allocated += lv_ptr->lv_allocated_snapshot_le;
1774 - if ((ret = lvm_snapshot_alloc(lv_ptr)) !=
1776 + if ((ret = lvm_snapshot_alloc(lv_ptr)) != 0)
1778 vfree(lv_ptr->lv_block_exception);
1780 vg_ptr->lv[l] = NULL;
1783 - for (e = 0; e < lv_ptr->lv_remap_ptr; e++)
1784 - lvm_hash_link(lv_ptr->
1785 - lv_block_exception +
1788 - lv_block_exception
1791 - lv_block_exception
1794 + for ( e = 0; e < lv_ptr->lv_remap_ptr; e++)
1795 + lvm_hash_link (lv_ptr->lv_block_exception + e,
1796 + lv_ptr->lv_block_exception[e].rdev_org,
1797 + lv_ptr->lv_block_exception[e].rsector_org, lv_ptr);
1798 /* need to fill the COW exception table data
1799 into the page for disk i/o */
1800 - if (lvm_snapshot_fill_COW_page
1801 - (vg_ptr, lv_ptr)) {
1802 + if(lvm_snapshot_fill_COW_page(vg_ptr, lv_ptr)) {
1804 vg_ptr->lv[l] = NULL;
1807 - init_waitqueue_head(&lv_ptr->
1808 - lv_snapshot_wait);
1809 + init_waitqueue_head(&lv_ptr->lv_snapshot_wait);
1812 vg_ptr->lv[l] = NULL;
1813 @@ -2159,7 +2152,7 @@
1814 vg_ptr->lv[l] = NULL;
1817 - } /* if ( vg[VG_CHR(minor)]->lv[l]->lv_access & LV_SNAPSHOT) */
1818 + } /* if ( vg[VG_CHR(minor)]->lv[l]->lv_access & LV_SNAPSHOT) */
1820 lv_ptr = vg_ptr->lv[l];
1821 lvm_gendisk.part[MINOR(lv_ptr->lv_dev)].start_sect = 0;
1822 @@ -2187,24 +2180,23 @@
1824 down_write(&org->lv_lock);
1825 org->lv_access |= LV_SNAPSHOT_ORG;
1826 - lv_ptr->lv_access &= ~LV_SNAPSHOT_ORG; /* this can only hide an userspace bug */
1827 + lv_ptr->lv_access &= ~LV_SNAPSHOT_ORG; /* this can only hide an userspace bug */
1830 /* Link in the list of snapshot volumes */
1831 - for (last = org; last->lv_snapshot_next;
1832 - last = last->lv_snapshot_next);
1833 + for (last = org; last->lv_snapshot_next; last = last->lv_snapshot_next);
1834 lv_ptr->lv_snapshot_prev = last;
1835 last->lv_snapshot_next = lv_ptr;
1836 up_write(&org->lv_lock);
1839 /* activate the logical volume */
1842 lv_ptr->lv_status |= LV_ACTIVE;
1844 lv_ptr->lv_status &= ~LV_ACTIVE;
1846 - if (lv_ptr->lv_access & LV_WRITE)
1847 + if ( lv_ptr->lv_access & LV_WRITE)
1848 set_device_ro(lv_ptr->lv_dev, 0);
1850 set_device_ro(lv_ptr->lv_dev, 1);
1851 @@ -2218,7 +2210,7 @@
1852 lvm_gendisk.part[MINOR(lv_ptr->lv_dev)].de =
1853 lvm_fs_create_lv(vg_ptr, lv_ptr);
1855 -} /* lvm_do_lv_create() */
1856 +} /* lvm_do_lv_create() */
1860 @@ -2230,6 +2222,9 @@
1861 vg_t *vg_ptr = vg[VG_CHR(minor)];
1868 for (l = 0; l < vg_ptr->lv_max; l++) {
1869 if (vg_ptr->lv[l] != NULL &&
1870 @@ -2238,8 +2233,7 @@
1874 - if (l == vg_ptr->lv_max)
1876 + if (l == vg_ptr->lv_max) return -ENXIO;
1878 lv_ptr = vg_ptr->lv[l];
1879 #ifdef LVM_TOTAL_RESET
1880 @@ -2262,12 +2256,11 @@
1881 * Atomically make the the snapshot invisible
1882 * to the original lv before playing with it.
1884 - lv_t *org = lv_ptr->lv_snapshot_org;
1885 + lv_t * org = lv_ptr->lv_snapshot_org;
1886 down_write(&org->lv_lock);
1888 /* remove this snapshot logical volume from the chain */
1889 - lv_ptr->lv_snapshot_prev->lv_snapshot_next =
1890 - lv_ptr->lv_snapshot_next;
1891 + lv_ptr->lv_snapshot_prev->lv_snapshot_next = lv_ptr->lv_snapshot_next;
1892 if (lv_ptr->lv_snapshot_next != NULL) {
1893 lv_ptr->lv_snapshot_next->lv_snapshot_prev =
1894 lv_ptr->lv_snapshot_prev;
1895 @@ -2306,7 +2299,7 @@
1896 vg_lv_map[MINOR(lv_ptr->lv_dev)].lv_number = -1;
1898 /* correct the PE count in PVs if this is not a snapshot
1901 if (!(lv_ptr->lv_access & LV_SNAPSHOT)) {
1902 /* only if this is no snapshot logical volume because
1903 we share the lv_current_pe[] structs with the
1904 @@ -2327,15 +2320,13 @@
1905 vg_ptr->lv[l] = NULL;
1908 -} /* lvm_do_lv_remove() */
1909 +} /* lvm_do_lv_remove() */
1913 * logical volume extend / reduce
1915 -static int __extend_reduce_snapshot(vg_t * vg_ptr, lv_t * old_lv,
1918 +static int __extend_reduce_snapshot(vg_t *vg_ptr, lv_t *old_lv, lv_t *new_lv) {
1920 lv_block_exception_t *lvbe;
1922 @@ -2366,8 +2357,7 @@
1926 -static int __extend_reduce(vg_t * vg_ptr, lv_t * old_lv, lv_t * new_lv)
1928 +static int __extend_reduce(vg_t *vg_ptr, lv_t *old_lv, lv_t *new_lv) {
1929 ulong size, l, p, end;
1932 @@ -2383,7 +2373,7 @@
1934 /* get the PE structures from user space */
1935 if (copy_from_user(pe, new_lv->lv_current_pe, size)) {
1936 - if (old_lv->lv_access & LV_SNAPSHOT)
1937 + if(old_lv->lv_access & LV_SNAPSHOT)
1938 vfree(new_lv->lv_snapshot_hash_table);
1941 @@ -2408,7 +2398,7 @@
1942 vg_ptr->pe_allocated++;
1943 for (p = 0; p < vg_ptr->pv_cur; p++) {
1944 if (vg_ptr->pv[p]->pv_dev ==
1945 - new_lv->lv_current_pe[l].dev) {
1946 + new_lv->lv_current_pe[l].dev) {
1947 vg_ptr->pv[p]->pe_allocated++;
1950 @@ -2420,30 +2410,25 @@
1951 end = min(old_lv->lv_current_le, new_lv->lv_current_le);
1952 for (l = 0; l < end; l++) {
1953 new_lv->lv_current_pe[l].reads +=
1954 - old_lv->lv_current_pe[l].reads;
1955 + old_lv->lv_current_pe[l].reads;
1957 new_lv->lv_current_pe[l].writes +=
1958 - old_lv->lv_current_pe[l].writes;
1959 + old_lv->lv_current_pe[l].writes;
1962 } else { /* striped logical volume */
1963 - uint i, j, source, dest, end, old_stripe_size,
1965 + uint i, j, source, dest, end, old_stripe_size, new_stripe_size;
1968 - old_lv->lv_allocated_le / old_lv->lv_stripes;
1970 - new_lv->lv_allocated_le / new_lv->lv_stripes;
1971 + old_stripe_size = old_lv->lv_allocated_le / old_lv->lv_stripes;
1972 + new_stripe_size = new_lv->lv_allocated_le / new_lv->lv_stripes;
1973 end = min(old_stripe_size, new_stripe_size);
1975 for (i = source = dest = 0; i < new_lv->lv_stripes; i++) {
1976 for (j = 0; j < end; j++) {
1977 new_lv->lv_current_pe[dest + j].reads +=
1978 - old_lv->lv_current_pe[source +
1980 + old_lv->lv_current_pe[source + j].reads;
1981 new_lv->lv_current_pe[dest + j].writes +=
1982 - old_lv->lv_current_pe[source +
1984 + old_lv->lv_current_pe[source + j].writes;
1986 source += old_stripe_size;
1987 dest += new_stripe_size;
1988 @@ -2453,7 +2438,7 @@
1992 -static int lvm_do_lv_extend_reduce(int minor, char *lv_name, lv_t * new_lv)
1993 +static int lvm_do_lv_extend_reduce(int minor, char *lv_name, lv_t *new_lv)
1997 @@ -2461,12 +2446,15 @@
2004 if ((pe = new_lv->lv_current_pe) == NULL)
2007 for (l = 0; l < vg_ptr->lv_max; l++)
2009 - && !strcmp(vg_ptr->lv[l]->lv_name, lv_name)) break;
2010 + if (vg_ptr->lv[l] && !strcmp(vg_ptr->lv[l]->lv_name, lv_name))
2013 if (l == vg_ptr->lv_max)
2015 @@ -2476,24 +2464,22 @@
2016 if (old_lv->lv_access & LV_SNAPSHOT) {
2017 /* only perform this operation on active snapshots */
2018 if (old_lv->lv_status & LV_ACTIVE)
2020 - __extend_reduce_snapshot(vg_ptr, old_lv,
2022 + r = __extend_reduce_snapshot(vg_ptr, old_lv, new_lv);
2027 r = __extend_reduce(vg_ptr, old_lv, new_lv);
2033 /* copy relevent fields */
2034 down_write(&old_lv->lv_lock);
2036 - if (new_lv->lv_access & LV_SNAPSHOT) {
2037 + if(new_lv->lv_access & LV_SNAPSHOT) {
2038 size = (new_lv->lv_remap_end > old_lv->lv_remap_end) ?
2039 - old_lv->lv_remap_ptr : new_lv->lv_remap_end;
2040 + old_lv->lv_remap_ptr : new_lv->lv_remap_end;
2041 size *= sizeof(lv_block_exception_t);
2042 memcpy(new_lv->lv_block_exception,
2043 old_lv->lv_block_exception, size);
2044 @@ -2501,18 +2487,17 @@
2045 old_lv->lv_remap_end = new_lv->lv_remap_end;
2046 old_lv->lv_block_exception = new_lv->lv_block_exception;
2047 old_lv->lv_snapshot_hash_table =
2048 - new_lv->lv_snapshot_hash_table;
2049 + new_lv->lv_snapshot_hash_table;
2050 old_lv->lv_snapshot_hash_table_size =
2051 - new_lv->lv_snapshot_hash_table_size;
2052 + new_lv->lv_snapshot_hash_table_size;
2053 old_lv->lv_snapshot_hash_mask =
2054 - new_lv->lv_snapshot_hash_mask;
2055 + new_lv->lv_snapshot_hash_mask;
2057 for (e = 0; e < new_lv->lv_remap_ptr; e++)
2058 lvm_hash_link(new_lv->lv_block_exception + e,
2059 - new_lv->lv_block_exception[e].
2061 - new_lv->lv_block_exception[e].
2062 - rsector_org, new_lv);
2063 + new_lv->lv_block_exception[e].rdev_org,
2064 + new_lv->lv_block_exception[e].rsector_org,
2069 @@ -2524,26 +2509,24 @@
2070 old_lv->lv_current_le = new_lv->lv_current_le;
2071 old_lv->lv_current_pe = new_lv->lv_current_pe;
2072 lvm_gendisk.part[MINOR(old_lv->lv_dev)].nr_sects =
2075 lvm_size[MINOR(old_lv->lv_dev)] = old_lv->lv_size >> 1;
2077 if (old_lv->lv_access & LV_SNAPSHOT_ORG) {
2079 - for (snap = old_lv->lv_snapshot_next; snap;
2080 - snap = snap->lv_snapshot_next) {
2081 + for(snap = old_lv->lv_snapshot_next; snap;
2082 + snap = snap->lv_snapshot_next) {
2083 down_write(&snap->lv_lock);
2084 - snap->lv_current_pe =
2085 - old_lv->lv_current_pe;
2086 + snap->lv_current_pe = old_lv->lv_current_pe;
2087 snap->lv_allocated_le =
2088 - old_lv->lv_allocated_le;
2089 - snap->lv_current_le =
2090 - old_lv->lv_current_le;
2091 + old_lv->lv_allocated_le;
2092 + snap->lv_current_le = old_lv->lv_current_le;
2093 snap->lv_size = old_lv->lv_size;
2095 - lvm_gendisk.part[MINOR(snap->lv_dev)].
2096 - nr_sects = old_lv->lv_size;
2097 + lvm_gendisk.part[MINOR(snap->lv_dev)].nr_sects
2098 + = old_lv->lv_size;
2099 lvm_size[MINOR(snap->lv_dev)] =
2100 - old_lv->lv_size >> 1;
2101 + old_lv->lv_size >> 1;
2102 __update_hardsectsize(snap);
2103 up_write(&snap->lv_lock);
2105 @@ -2554,13 +2537,13 @@
2106 up_write(&old_lv->lv_lock);
2109 -} /* lvm_do_lv_extend_reduce() */
2110 +} /* lvm_do_lv_extend_reduce() */
2114 * character device support function logical volume status by name
2116 -static int lvm_do_lv_status_byname(vg_t * vg_ptr, void *arg)
2117 +static int lvm_do_lv_status_byname(vg_t *vg_ptr, void *arg)
2120 lv_status_byname_req_t lv_status_byname_req;
2121 @@ -2568,206 +2551,181 @@
2125 - if (vg_ptr == NULL)
2127 + if (vg_ptr == NULL) return -ENXIO;
2128 if (copy_from_user(&lv_status_byname_req, arg,
2129 sizeof(lv_status_byname_req_t)) != 0)
2132 - if (lv_status_byname_req.lv == NULL)
2134 + if (lv_status_byname_req.lv == NULL) return -EINVAL;
2136 for (l = 0; l < vg_ptr->lv_max; l++) {
2137 if ((lv_ptr = vg_ptr->lv[l]) != NULL &&
2138 strcmp(lv_ptr->lv_name,
2139 lv_status_byname_req.lv_name) == 0) {
2140 - /* Save usermode pointers */
2141 - if (copy_from_user
2143 - &lv_status_byname_req.lv->lv_current_pe,
2144 - sizeof(void *)) != 0)
2146 - if (copy_from_user
2148 - &lv_status_byname_req.lv->lv_block_exception,
2149 - sizeof(void *)) != 0)
2150 + /* Save usermode pointers */
2151 + if (copy_from_user(&saved_ptr1, &lv_status_byname_req.lv->lv_current_pe, sizeof(void*)) != 0)
2153 - if (copy_to_user(lv_status_byname_req.lv,
2154 - lv_ptr, sizeof(lv_t)) != 0)
2155 + if (copy_from_user(&saved_ptr2, &lv_status_byname_req.lv->lv_block_exception, sizeof(void*)) != 0)
2157 + if (copy_to_user(lv_status_byname_req.lv,
2159 + sizeof(lv_t)) != 0)
2161 if (saved_ptr1 != NULL) {
2162 if (copy_to_user(saved_ptr1,
2163 lv_ptr->lv_current_pe,
2164 lv_ptr->lv_allocated_le *
2165 - sizeof(pe_t)) != 0)
2166 + sizeof(pe_t)) != 0)
2169 /* Restore usermode pointers */
2171 - (&lv_status_byname_req.lv->lv_current_pe,
2172 - &saved_ptr1, sizeof(void *)) != 0)
2174 + if (copy_to_user(&lv_status_byname_req.lv->lv_current_pe, &saved_ptr1, sizeof(void*)) != 0)
2180 -} /* lvm_do_lv_status_byname() */
2181 +} /* lvm_do_lv_status_byname() */
2185 * character device support function logical volume status by index
2187 -static int lvm_do_lv_status_byindex(vg_t * vg_ptr, void *arg)
2188 +static int lvm_do_lv_status_byindex(vg_t *vg_ptr,void *arg)
2190 lv_status_byindex_req_t lv_status_byindex_req;
2195 - if (vg_ptr == NULL)
2197 + if (vg_ptr == NULL) return -ENXIO;
2198 if (copy_from_user(&lv_status_byindex_req, arg,
2199 sizeof(lv_status_byindex_req)) != 0)
2202 if (lv_status_byindex_req.lv == NULL)
2204 - if (lv_status_byindex_req.lv_index < 0 ||
2205 - lv_status_byindex_req.lv_index >= MAX_LV)
2207 - if ((lv_ptr = vg_ptr->lv[lv_status_byindex_req.lv_index]) == NULL)
2208 + if ( ( lv_ptr = vg_ptr->lv[lv_status_byindex_req.lv_index]) == NULL)
2211 /* Save usermode pointers */
2212 - if (copy_from_user
2213 - (&saved_ptr1, &lv_status_byindex_req.lv->lv_current_pe,
2214 - sizeof(void *)) != 0)
2216 - if (copy_from_user
2217 - (&saved_ptr2, &lv_status_byindex_req.lv->lv_block_exception,
2218 - sizeof(void *)) != 0)
2220 + if (copy_from_user(&saved_ptr1, &lv_status_byindex_req.lv->lv_current_pe, sizeof(void*)) != 0)
2222 + if (copy_from_user(&saved_ptr2, &lv_status_byindex_req.lv->lv_block_exception, sizeof(void*)) != 0)
2225 - if (copy_to_user(lv_status_byindex_req.lv, lv_ptr, sizeof(lv_t)) !=
2226 - 0) return -EFAULT;
2227 + if (copy_to_user(lv_status_byindex_req.lv, lv_ptr, sizeof(lv_t)) != 0)
2229 if (saved_ptr1 != NULL) {
2230 if (copy_to_user(saved_ptr1,
2231 lv_ptr->lv_current_pe,
2232 lv_ptr->lv_allocated_le *
2233 - sizeof(pe_t)) != 0) return -EFAULT;
2234 + sizeof(pe_t)) != 0)
2238 /* Restore usermode pointers */
2240 - (&lv_status_byindex_req.lv->lv_current_pe, &saved_ptr1,
2241 - sizeof(void *)) != 0)
2243 + if (copy_to_user(&lv_status_byindex_req.lv->lv_current_pe, &saved_ptr1, sizeof(void *)) != 0)
2247 -} /* lvm_do_lv_status_byindex() */
2248 +} /* lvm_do_lv_status_byindex() */
2252 * character device support function logical volume status by device number
2254 -static int lvm_do_lv_status_bydev(vg_t * vg_ptr, void *arg)
2256 +static int lvm_do_lv_status_bydev(vg_t * vg_ptr, void * arg) {
2258 lv_status_bydev_req_t lv_status_bydev_req;
2263 - if (vg_ptr == NULL)
2265 + if (vg_ptr == NULL) return -ENXIO;
2266 if (copy_from_user(&lv_status_bydev_req, arg,
2267 sizeof(lv_status_bydev_req)) != 0)
2270 - for (l = 0; l < vg_ptr->lv_max; l++) {
2271 - if (vg_ptr->lv[l] == NULL)
2273 - if (vg_ptr->lv[l]->lv_dev == lv_status_bydev_req.dev)
2275 + for ( l = 0; l < vg_ptr->lv_max; l++) {
2276 + if ( vg_ptr->lv[l] == NULL) continue;
2277 + if ( vg_ptr->lv[l]->lv_dev == lv_status_bydev_req.dev) break;
2280 - if (l == vg_ptr->lv_max)
2282 + if ( l == vg_ptr->lv_max) return -ENXIO;
2283 lv_ptr = vg_ptr->lv[l];
2285 /* Save usermode pointers */
2286 - if (copy_from_user
2287 - (&saved_ptr1, &lv_status_bydev_req.lv->lv_current_pe,
2288 - sizeof(void *)) != 0)
2290 - if (copy_from_user
2291 - (&saved_ptr2, &lv_status_bydev_req.lv->lv_block_exception,
2292 - sizeof(void *)) != 0)
2294 + if (copy_from_user(&saved_ptr1, &lv_status_bydev_req.lv->lv_current_pe, sizeof(void*)) != 0)
2296 + if (copy_from_user(&saved_ptr2, &lv_status_bydev_req.lv->lv_block_exception, sizeof(void*)) != 0)
2299 - if (copy_to_user(lv_status_bydev_req.lv, lv_ptr, sizeof(lv_t)) !=
2300 - 0) return -EFAULT;
2301 + if (copy_to_user(lv_status_bydev_req.lv, lv_ptr, sizeof(lv_t)) != 0)
2303 if (saved_ptr1 != NULL) {
2304 if (copy_to_user(saved_ptr1,
2305 lv_ptr->lv_current_pe,
2306 lv_ptr->lv_allocated_le *
2307 - sizeof(pe_t)) != 0) return -EFAULT;
2308 + sizeof(pe_t)) != 0)
2311 /* Restore usermode pointers */
2313 - (&lv_status_bydev_req.lv->lv_current_pe, &saved_ptr1,
2314 - sizeof(void *)) != 0)
2316 + if (copy_to_user(&lv_status_bydev_req.lv->lv_current_pe, &saved_ptr1, sizeof(void *)) != 0)
2320 -} /* lvm_do_lv_status_bydev() */
2321 +} /* lvm_do_lv_status_bydev() */
2325 * character device support function rename a logical volume
2327 -static int lvm_do_lv_rename(vg_t * vg_ptr, lv_req_t * lv_req, lv_t * lv)
2328 +static int lvm_do_lv_rename(vg_t *vg_ptr, lv_req_t *lv_req, lv_t *lv)
2332 lv_t *lv_ptr = NULL;
2334 - for (l = 0; l < vg_ptr->lv_max; l++) {
2335 - if ((lv_ptr = vg_ptr->lv[l]) == NULL)
2337 - if (lv_ptr->lv_dev == lv->lv_dev) {
2341 + for (l = 0; l < vg_ptr->lv_max; l++)
2343 + if ( (lv_ptr = vg_ptr->lv[l]) == NULL) continue;
2344 + if (lv_ptr->lv_dev == lv->lv_dev)
2346 lvm_fs_remove_lv(vg_ptr, lv_ptr);
2347 - strncpy(lv_ptr->lv_name, lv_req->lv_name,
2349 + strncpy(lv_ptr->lv_name, lv_req->lv_name, NAME_LEN);
2350 lvm_fs_create_lv(vg_ptr, lv_ptr);
2354 - if (l == vg_ptr->lv_max)
2356 + if (l == vg_ptr->lv_max) ret = -ENODEV;
2359 -} /* lvm_do_lv_rename */
2360 +} /* lvm_do_lv_rename */
2364 * character device support function physical volume change
2366 -static int lvm_do_pv_change(vg_t * vg_ptr, void *arg)
2367 +static int lvm_do_pv_change(vg_t *vg_ptr, void *arg)
2371 struct block_device *bd;
2373 - if (vg_ptr == NULL)
2375 + if (vg_ptr == NULL) return -ENXIO;
2376 if (copy_from_user(&pv_change_req, arg,
2377 - sizeof(pv_change_req)) != 0) return -EFAULT;
2378 + sizeof(pv_change_req)) != 0)
2381 for (p = 0; p < vg_ptr->pv_max; p++) {
2382 pv_ptr = vg_ptr->pv[p];
2383 if (pv_ptr != NULL &&
2384 - strcmp(pv_ptr->pv_name, pv_change_req.pv_name) == 0) {
2385 + strcmp(pv_ptr->pv_name,
2386 + pv_change_req.pv_name) == 0) {
2389 if (copy_from_user(pv_ptr,
2390 @@ -2783,33 +2741,35 @@
2394 -} /* lvm_do_pv_change() */
2395 +} /* lvm_do_pv_change() */
2398 * character device support function get physical volume status
2400 -static int lvm_do_pv_status(vg_t * vg_ptr, void *arg)
2401 +static int lvm_do_pv_status(vg_t *vg_ptr, void *arg)
2406 - if (vg_ptr == NULL)
2408 + if (vg_ptr == NULL) return -ENXIO;
2409 if (copy_from_user(&pv_status_req, arg,
2410 - sizeof(pv_status_req)) != 0) return -EFAULT;
2411 + sizeof(pv_status_req)) != 0)
2414 for (p = 0; p < vg_ptr->pv_max; p++) {
2415 pv_ptr = vg_ptr->pv[p];
2416 if (pv_ptr != NULL &&
2417 - strcmp(pv_ptr->pv_name, pv_status_req.pv_name) == 0) {
2418 + strcmp(pv_ptr->pv_name,
2419 + pv_status_req.pv_name) == 0) {
2420 if (copy_to_user(pv_status_req.pv,
2421 - pv_ptr, sizeof(pv_t)) != 0)
2423 + sizeof(pv_t)) != 0)
2429 -} /* lvm_do_pv_status() */
2430 +} /* lvm_do_pv_status() */
2434 @@ -2851,15 +2811,13 @@
2435 hardsect_size[MAJOR_NR] = lvm_hardsectsizes;
2438 -} /* lvm_gen_init() */
2439 +} /* lvm_gen_init() */
2443 /* Must have down_write(_pe_lock) when we enqueue buffers */
2444 -static void _queue_io(struct buffer_head *bh, int rw)
2446 - if (bh->b_reqnext)
2448 +static void _queue_io(struct buffer_head *bh, int rw) {
2449 + if (bh->b_reqnext) BUG();
2450 bh->b_reqnext = _pe_requests;
2453 @@ -2897,15 +2855,14 @@
2455 * we must open the pv's before we use them
2457 -static int _open_pv(pv_t * pv)
2459 +static int _open_pv(pv_t *pv) {
2461 struct block_device *bd;
2463 if (!(bd = bdget(kdev_t_to_nr(pv->pv_dev))))
2466 - err = blkdev_get(bd, FMODE_READ | FMODE_WRITE, 0, BDEV_FILE);
2467 + err = blkdev_get(bd, FMODE_READ|FMODE_WRITE, 0, BDEV_FILE);
2471 @@ -2913,8 +2870,7 @@
2475 -static void _close_pv(pv_t * pv)
2477 +static void _close_pv(pv_t *pv) {
2479 struct block_device *bdev = pv->bd;
2481 @@ -2926,7 +2882,7 @@
2483 static unsigned long _sectors_to_k(unsigned long sect)
2485 - if (SECTOR_SIZE > 1024) {
2486 + if(SECTOR_SIZE > 1024) {
2487 return sect * (SECTOR_SIZE / 1024);
2490 diff -u -r linux-2.4.19-rc3.orig/include/linux/lvm.h linux-2.4.19-rc3/include/linux/lvm.h
2491 --- linux-2.4.19-rc3.orig/include/linux/lvm.h Thu Jul 25 13:05:18 2002
2492 +++ linux-2.4.19-rc3/include/linux/lvm.h Thu Jul 25 13:46:01 2002
2497 - * Copyright (C) 1997 - 2001 Heinz Mauelshagen, Sistina Software
2498 + * Copyright (C) 1997 - 2002 Heinz Mauelshagen, Sistina Software
2500 * February-November 1997
2502 * January-March,July,September,October,Dezember 1999
2503 * January,February,July,November 2000
2504 * January-March,June,July 2001
2507 * lvm is free software; you can redistribute it and/or modify
2508 * it under the terms of the GNU General Public License as published by
2510 #ifndef _LVM_H_INCLUDE
2511 #define _LVM_H_INCLUDE
2513 -#define LVM_RELEASE_NAME "1.0.3"
2514 -#define LVM_RELEASE_DATE "19/02/2002"
2515 +#define LVM_RELEASE_NAME "1.0.5+"
2516 +#define LVM_RELEASE_DATE "22/07/2002"
2518 #define _LVM_KERNEL_H_VERSION "LVM "LVM_RELEASE_NAME" ("LVM_RELEASE_DATE")"
2520 @@ -208,40 +209,35 @@
2522 * VGDA: default disk spaces and offsets
2524 - * There's space after the structures for later extensions.
2525 - * The physical volume structure holds offset and size definitions
2526 - * for itself (well, kind of redundant ;-) and all other structure{s| arrays};
2528 - * In recent versions since LVM 0.9.1 we align to 4k offsets in order to ease
2529 - * future kernel reads of the metadata.
2531 - * offset what size
2532 - * --------------- -------------------------------- ------------
2533 - * 0 physical volume structure pv->pv_on_disk.size
2535 - * pv->vg_on_disk.base volume group structure pv->vg_on_disk.size
2537 - * pv->uuidlist_on_disk.base 128 byte each
2538 - * uuidlist of physical volumes
2539 - * holding one uuid per physical volume
2540 + * there's space after the structures for later extensions.
2542 - * pv->lv_on_disk.base logical volume structures; pv->lv_on_disk.size
2543 - * one structure per logical volume (~300 byte each)
2544 + * offset what size
2545 + * --------------- ---------------------------------- ------------
2546 + * 0 physical volume structure ~500 byte
2548 - * pv->pe_on_disk.base physical extent alloc. structs pv->pe_on_disk.size
2549 - * one strcuture per physical extent (4 byte each)
2550 + * 1K volume group structure ~200 byte
2552 - * End of disk - first physical extent default 4 megabyte
2553 + * 6K namelist of physical volumes 128 byte each
2555 + * 6k + n * ~300byte n logical volume structures ~300 byte each
2557 + * + m * 4byte m physical extent alloc. structs 4 byte each
2559 + * End of disk - first physical extent typically 4 megabyte
2562 - * (rounded to 64k offset today)
2564 - * pv->pe_on_disk.base + pv->pe_on_disk.size == start of first physical extent
2568 /* DONT TOUCH THESE !!! */
2577 * LVM_PE_T_MAX corresponds to:
2581 * Maximum PE size of 16GB gives a maximum logical volume size of 1024 TB.
2583 - * AFAIK, the actual kernels limit this to 2 TB.
2584 + * AFAIK, the actual kernels limit this to 1 TB.
2586 * Should be a sufficient spectrum ;*)
2589 #define LVM_MAX_MIRRORS 2 /* future use */
2590 #define LVM_MIN_READ_AHEAD 0 /* minimum read ahead sectors */
2591 #define LVM_DEFAULT_READ_AHEAD 1024 /* sectors for 512k scsi segments */
2592 -#define LVM_MAX_READ_AHEAD 10000 /* maximum read ahead sectors */
2593 +#define LVM_MAX_READ_AHEAD 1024 /* maximum read ahead sectors */
2594 #define LVM_MAX_LV_IO_TIMEOUT 60 /* seconds I/O timeout (future use) */
2595 #define LVM_PARTITION 0xfe /* LVM partition id */
2596 #define LVM_NEW_PARTITION 0x8e /* new LVM partition id (10/09/1999) */