]> git.pld-linux.org Git - packages/kernel.git/blob - lvm_1.0.5+_25.07.2002.patch
- added description of djurban's branch
[packages/kernel.git] / lvm_1.0.5+_25.07.2002.patch
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
4 @@ -1,9 +1,10 @@
5  /*
6   * kernel/lvm-fs.c
7   *
8 - * Copyright (C) 2001 Sistina Software
9 + * Copyright (C) 2001-2002 Sistina Software
10   *
11 - * January-April 2001
12 + * January-May,December 2001
13 + * May 2002
14   *
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
17 @@ -108,6 +109,9 @@
18  void lvm_fs_create_vg(vg_t *vg_ptr) {
19         struct proc_dir_entry *pde;
20  
21 +       if (!vg_ptr)
22 +               return;
23 +
24         vg_devfs_handle[vg_ptr->vg_number] =
25                 devfs_mk_dir(0, vg_ptr->vg_name, NULL);
26  
27 @@ -135,22 +139,24 @@
28  void lvm_fs_remove_vg(vg_t *vg_ptr) {
29         int i;
30  
31 +       if (!vg_ptr)
32 +               return;
33 +
34         devfs_unregister(ch_devfs_handle[vg_ptr->vg_number]);
35         ch_devfs_handle[vg_ptr->vg_number] = NULL;
36  
37 -       /* remove pv's */
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]);
40 -
41         /* remove lv's */
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]);
44  
45 -
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;
49  
50 +       /* remove pv's */
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]);
53 +
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;
57 @@ -174,7 +180,12 @@
58  
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);
62 +       const char *name;
63 +
64 +       if (!vg_ptr || !lv)
65 +               return NULL;
66 +
67 +       name = _basename(lv->lv_name);
68  
69         lv_devfs_handle[MINOR(lv->lv_dev)] = devfs_register(
70                 vg_devfs_handle[vg_ptr->vg_number], name,
71 @@ -191,6 +202,10 @@
72  }
73  
74  void lvm_fs_remove_lv(vg_t *vg_ptr, lv_t *lv) {
75 +
76 +       if (!vg_ptr || !lv)
77 +               return;
78 +
79         devfs_unregister(lv_devfs_handle[MINOR(lv->lv_dev)]);
80         lv_devfs_handle[MINOR(lv->lv_dev)] = NULL;
81  
82 @@ -219,6 +234,9 @@
83         struct proc_dir_entry *pde;
84         char name[NAME_LEN];
85  
86 +       if (!vg_ptr || !pv)
87 +               return;
88 +
89         if(!vg_ptr->pv_subdir_pde)
90                 return;
91  
92 @@ -232,6 +250,9 @@
93  void lvm_fs_remove_pv(vg_t *vg_ptr, pv_t *pv) {
94         char name[NAME_LEN];
95  
96 +       if (!vg_ptr || !pv)
97 +               return;
98 +
99         if(!vg_ptr->pv_subdir_pde)
100                 return;
101  
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
105 @@ -49,6 +49,10 @@
106  extern vg_t *vg[];
107  extern struct file_operations lvm_chr_fops;
108  
109 +#ifndef        uchar
110 +typedef        unsigned char   uchar;
111 +#endif
112 +
113  extern struct block_device_operations lvm_blk_dops;
114  
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
119 @@ -2,7 +2,7 @@
120   * kernel/lvm-snap.c
121   *
122   * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
123 - *               2000 - 2001 Heinz Mauelshagen, Sistina Software
124 + *               2000 - 2002 Heinz Mauelshagen, Sistina Software
125   *
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
128 @@ -41,6 +41,7 @@
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]
133   *
134   */
135  
136 @@ -125,8 +126,11 @@
137                         if (i)
138                         {
139                                 /* fun, isn't it? :) */
140 +#ifdef list_move
141 +                               list_move(next, hash_table);
142 +#else
143                                 list_del(next);
144 -                               list_add(next, hash_table);
145 +#endif                         list_add(next, hash_table);
146                         }
147                         ret = exception;
148                         break;
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
152 @@ -1,13 +1,14 @@
153  /*
154   * kernel/lvm.c
155   *
156 - * Copyright (C) 1997 - 2001  Heinz Mauelshagen, Sistina Software
157 + * Copyright (C) 1997 - 2002  Heinz Mauelshagen, Sistina Software
158   *
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
165 + * May-July 2002
166   *
167   *
168   * LVM driver is free software; you can redistribute it and/or modify
169 @@ -214,6 +215,11 @@
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
178   *
179   */
180  
181 @@ -277,14 +283,13 @@
182  /*
183   * External function prototypes
184   */
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*);
188  
189  static int lvm_blk_ioctl(struct inode *, struct file *, uint, ulong);
190  static int lvm_blk_open(struct inode *, struct file *);
191  
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 *);
196  
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 *);
206  
207 -static int lvm_do_pe_lock_unlock(vg_t * r, void *);
208 +static int lvm_do_pe_lock_unlock(vg_t *r, void *);
209  
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 *);
214  
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);
221  
222  
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);
226  
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);
231  
232  static unsigned long _sectors_to_k(unsigned long sect);
233  
234 @@ -349,22 +354,20 @@
235  
236  
237  /* variables */
238 -char *lvm_version =
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;
242  int loadtime = 0;
243  const char *const lvm_name = LVM_NAME;
244  
245  
246  /* volume group descriptor area pointers */
247 -vg_t *vg[ABS_MAX_VG];
248 +vg_t *vg[ABS_MAX_VG + 1];
249  
250  /* map from block minor number to VG and LV numbers */
251 -typedef struct {
252 +static struct {
253         int vg_number;
254         int lv_number;
255 -} vg_lv_map_t;
256 -static vg_lv_map_t vg_lv_map[ABS_MAX_LV];
257 +} vg_lv_map[ABS_MAX_LV];
258  
259  
260  /* Request structures (lvm_chr_ioctl()) */
261 @@ -394,17 +397,19 @@
262  
263  
264  struct file_operations lvm_chr_fops = {
265 -       open:lvm_chr_open,
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,
272  };
273  
274  /* block device operations structure needed for 2.3.38? and above */
275 -struct block_device_operations lvm_blk_dops = {
276 -       owner:THIS_MODULE,
277 -       open:lvm_blk_open,
278 -       release:lvm_blk_close,
279 -       ioctl:lvm_blk_ioctl,
280 +struct block_device_operations lvm_blk_dops =
281 +{
282 +       owner:          THIS_MODULE,
283 +       open:           lvm_blk_open,
284 +       release:        lvm_blk_close,
285 +       ioctl:          lvm_blk_ioctl,
286  };
287  
288  
289 @@ -414,14 +419,15 @@
290  static int lvm_hardsectsizes[MAX_LV];
291  static int lvm_size[MAX_LV];
292  
293 -static struct gendisk lvm_gendisk = {
294 -       major:MAJOR_NR,
295 -       major_name:LVM_NAME,
296 -       minor_shift:0,
297 -       max_p:1,
298 -       part:lvm_hd_struct,
299 -       sizes:lvm_size,
300 -       nr_real:MAX_LV,
301 +static struct gendisk lvm_gendisk =
302 +{
303 +       major:          MAJOR_NR,
304 +       major_name:     LVM_NAME,
305 +       minor_shift:    0,
306 +       max_p:          1,
307 +       part:           lvm_hd_struct,
308 +       sizes:          lvm_size,
309 +       nr_real:        MAX_LV,
310  };
311  
312  
313 @@ -458,8 +464,7 @@
314         lvm_hd_name_ptr = lvm_hd_name;
315  #endif
316  
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);
320  
321  
322         /* initialise the pe lock */
323 @@ -477,7 +482,7 @@
324  #endif
325  
326         return 0;
327 -}                              /* lvm_init() */
328 +} /* lvm_init() */
329  
330  /*
331   * cleanup...
332 @@ -510,12 +515,11 @@
333         lvm_fin_fs();
334  
335  #ifdef MODULE
336 -       printk(KERN_INFO "%s -- Module successfully deactivated\n",
337 -              lvm_name);
338 +       printk(KERN_INFO "%s -- Module successfully deactivated\n", lvm_name);
339  #endif
340  
341         return;
342 -}                              /* lvm_cleanup() */
343 +}      /* lvm_cleanup() */
344  
345  /*
346   * support function to initialize lvm variables
347 @@ -534,7 +538,7 @@
348         pe_lock_req.data.pv_offset = 0;
349  
350         /* Initialize VG pointers */
351 -       for (v = 0; v < ABS_MAX_VG; v++)
352 +       for (v = 0; v < ABS_MAX_VG + 1; v++)
353                 vg[v] = NULL;
354  
355         /* Initialize LV -> VG association */
356 @@ -545,7 +549,7 @@
357         }
358  
359         return;
360 -}                              /* lvm_init_vars() */
361 +} /* lvm_init_vars() */
362  
363  
364  /********************************************************************
365 @@ -568,15 +572,13 @@
366               minor, VG_CHR(minor), MODE_TO_STR(file->f_mode), lock);
367  
368         /* super user validation */
369 -       if (!capable(CAP_SYS_ADMIN))
370 -               return -EACCES;
371 +       if (!capable(CAP_SYS_ADMIN)) return -EACCES;
372  
373         /* Group special file open */
374 -       if (VG_CHR(minor) > MAX_VG)
375 -               return -ENXIO;
376 +       if (VG_CHR(minor) > MAX_VG) return -ENXIO;
377  
378         spin_lock(&lvm_lock);
379 -       if (lock == current->pid)
380 +       if(lock == current->pid)
381                 _lock_open_count++;
382         spin_unlock(&lvm_lock);
383  
384 @@ -585,7 +587,7 @@
385         MOD_INC_USE_COUNT;
386  
387         return 0;
388 -}                              /* lvm_chr_open() */
389 +} /* lvm_chr_open() */
390  
391  
392  /*
393 @@ -602,19 +604,16 @@
394         uint extendable, l, v;
395         void *arg = (void *) a;
396         lv_t lv;
397 -       vg_t *vg_ptr = vg[VG_CHR(minor)];
398 +       vg_t* vg_ptr = vg[VG_CHR(minor)];
399  
400         /* otherwise cc will complain about unused variables */
401         (void) lvm_lock;
402  
403 -       P_IOCTL
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));
409  
410  #ifdef LVM_TOTAL_RESET
411 -       if (lvm_reset_spindown > 0)
412 -               return -EACCES;
413 +       if (lvm_reset_spindown > 0) return -EACCES;
414  #endif
415  
416         /* Main command switch */
417 @@ -626,8 +625,8 @@
418         case LVM_GET_IOP_VERSION:
419                 /* check lvm version to ensure driver/tools+lib
420                    interoperability */
421 -               if (copy_to_user(arg, &lvm_iop_version, sizeof(ushort)) !=
422 -                   0) return -EFAULT;
423 +               if (copy_to_user(arg, &lvm_iop_version, sizeof(ushort)) != 0)
424 +                       return -EFAULT;
425                 return 0;
426  
427  #ifdef LVM_TOTAL_RESET
428 @@ -635,8 +634,7 @@
429                 /* lock reset function */
430                 lvm_reset_spindown = 1;
431                 for (v = 0; v < ABS_MAX_VG; v++) {
432 -                       if (vg[v] != NULL)
433 -                               lvm_do_vg_remove(v);
434 +                       if (vg[v] != NULL) lvm_do_vg_remove(v);
435                 }
436  
437  #ifdef MODULE
438 @@ -644,28 +642,28 @@
439                         MOD_INC_USE_COUNT;
440                 while (GET_USE_COUNT(&__this_module) > 1)
441                         MOD_DEC_USE_COUNT;
442 -#endif                         /* MODULE */
443 +#endif /* MODULE */
444                 lock = 0;       /* release lock */
445                 wake_up_interruptible(&lvm_wait);
446                 return 0;
447 -#endif                         /* LVM_TOTAL_RESET */
448 +#endif /* LVM_TOTAL_RESET */
449  
450  
451         case LE_REMAP:
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);
455  
456         case PE_LOCK_UNLOCK:
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);
461  
462         case VG_CREATE_OLD:
463                 /* create a VGDA */
464                 return lvm_do_vg_create(arg, minor);
465  
466         case VG_CREATE:
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);
470  
471         case VG_EXTEND:
472 @@ -687,10 +685,9 @@
473  
474         case VG_SET_EXTENDABLE:
475                 /* set/clear extendability flag of volume group */
476 -               if (vg_ptr == NULL)
477 -                       return -ENXIO;
478 -               if (copy_from_user(&extendable, arg, sizeof(extendable)) !=
479 -                   0) return -EFAULT;
480 +               if (vg_ptr == NULL) return -ENXIO;
481 +               if (copy_from_user(&extendable, arg, sizeof(extendable)) != 0)
482 +                       return -EFAULT;
483  
484                 if (extendable == VG_EXTENDABLE ||
485                     extendable == ~VG_EXTENDABLE) {
486 @@ -698,15 +695,13 @@
487                                 vg_ptr->vg_status |= VG_EXTENDABLE;
488                         else
489                                 vg_ptr->vg_status &= ~VG_EXTENDABLE;
490 -               } else
491 -                       return -EINVAL;
492 +               } else return -EINVAL;
493                 return 0;
494  
495  
496         case VG_STATUS:
497                 /* get volume group data (only the vg_t struct) */
498 -               if (vg_ptr == NULL)
499 -                       return -ENXIO;
500 +               if (vg_ptr == NULL) return -ENXIO;
501                 if (copy_to_user(arg, vg_ptr, sizeof(vg_t)) != 0)
502                         return -EFAULT;
503                 return 0;
504 @@ -739,25 +734,21 @@
505         case LV_REMOVE:
506         case LV_RENAME:
507                 /* create, extend, reduce, remove or rename a logical volume */
508 -               if (vg_ptr == NULL)
509 -                       return -ENXIO;
510 +               if (vg_ptr == NULL) return -ENXIO;
511                 if (copy_from_user(&lv_req, arg, sizeof(lv_req)) != 0)
512                         return -EFAULT;
513  
514                 if (command != LV_REMOVE) {
515 -                       if (copy_from_user(&lv, lv_req.lv, sizeof(lv_t)) !=
516 -                           0) return -EFAULT;
517 +                       if (copy_from_user(&lv, lv_req.lv, sizeof(lv_t)) != 0)
518 +                               return -EFAULT;
519                 }
520                 switch (command) {
521                 case LV_CREATE:
522 -                       return lvm_do_lv_create(minor, lv_req.lv_name,
523 -                                               &lv);
524 +                       return lvm_do_lv_create(minor, lv_req.lv_name, &lv);
525  
526                 case LV_EXTEND:
527                 case LV_REDUCE:
528 -                       return lvm_do_lv_extend_reduce(minor,
529 -                                                      lv_req.lv_name,
530 -                                                      &lv);
531 +                       return lvm_do_lv_extend_reduce(minor, lv_req.lv_name, &lv);
532                 case LV_REMOVE:
533                         return lvm_do_lv_remove(minor, lv_req.lv_name, -1);
534  
535 @@ -785,12 +776,12 @@
536  
537         case PV_CHANGE:
538                 /* change a physical volume */
539 -               return lvm_do_pv_change(vg_ptr, arg);
540 +               return lvm_do_pv_change(vg_ptr,arg);
541  
542  
543         case PV_STATUS:
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);
547  
548  
549         case PV_FLUSH:
550 @@ -802,11 +793,11 @@
551                 printk(KERN_WARNING
552                        "%s -- lvm_chr_ioctl: unknown command 0x%x\n",
553                        lvm_name, command);
554 -               return -EINVAL;
555 +               return -ENOTTY;
556         }
557  
558         return 0;
559 -}                              /* lvm_chr_ioctl */
560 +} /* lvm_chr_ioctl */
561  
562  
563  /*
564 @@ -824,14 +815,12 @@
565         }
566  #endif
567  
568 -       if (lvm_chr_open_count > 0)
569 -               lvm_chr_open_count--;
570 +       if (lvm_chr_open_count > 0) lvm_chr_open_count--;
571  
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",
576 -                             lock);
577 +       if(lock == current->pid) {
578 +               if(!_lock_open_count) {
579 +                       P_DEV("chr_close: unlocking LVM for pid %d\n", lock);
580                         lock = 0;
581                         wake_up_interruptible(&lvm_wait);
582                 } else
583 @@ -842,7 +831,7 @@
584         MOD_DEC_USE_COUNT;
585  
586         return 0;
587 -}                              /* lvm_chr_close() */
588 +} /* lvm_chr_close() */
589  
590  
591  
592 @@ -862,8 +851,7 @@
593         vg_t *vg_ptr = vg[VG_BLK(minor)];
594  
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));
599  
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) {
609  
610                 /* Check parallel LV spindown (LV remove) */
611 -               if (lv_ptr->lv_status & LV_SPINDOWN)
612 -                       return -EPERM;
613 +               if (lv_ptr->lv_status & LV_SPINDOWN) return -EPERM;
614  
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)))
621 +                   return -EPERM;
622  
623                 if (!(lv_ptr->lv_access & LV_WRITE) &&
624 -                   (file->f_mode & FMODE_WRITE)) return -EACCES;
625 +                   (file->f_mode & FMODE_WRITE))
626 +                       return -EACCES;
627  
628  
629 -               /* be sure to increment VG counter */
630 -               if (lv_ptr->lv_open == 0)
631 -                       vg_ptr->lv_open++;
632 +                /* be sure to increment VG counter */
633 +               if (lv_ptr->lv_open == 0) vg_ptr->lv_open++;
634                 lv_ptr->lv_open++;
635  
636                 MOD_INC_USE_COUNT;
637 @@ -901,157 +890,161 @@
638                 return 0;
639         }
640         return -ENXIO;
641 -}                              /* lvm_blk_open() */
642 -
643 +} /* lvm_blk_open() */
644  
645 -/*
646 - * block device i/o-control routine
647 - */
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)
652  {
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;
658 -
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));
662 -
663 -       switch (command) {
664 -       case BLKSSZGET:
665 -               /* get block device sector size as needed e.g. by fdisk */
666 -               return put_user(lvm_sectsize(inode->i_rdev), (int *) arg);
667 -
668 -       case BLKGETSIZE:
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))
672 -                       return -EFAULT;
673 -               break;
674 -
675 -#ifdef BLKGETSIZE64
676 -       case BLKGETSIZE64:
677 -               if (put_user((u64) lv_ptr->lv_size << 9, (u64 *) arg))
678 -                       return -EFAULT;
679 -               break;
680 -#endif
681 -
682 -       case BLKFLSBUF:
683 -               /* flush buffer cache */
684 -               if (!capable(CAP_SYS_ADMIN))
685 -                       return -EACCES;
686 -
687 -               P_IOCTL("BLKFLSBUF\n");
688 -
689 -               fsync_dev(inode->i_rdev);
690 -               invalidate_buffers(inode->i_rdev);
691 -               break;
692 -
693 -
694 -       case BLKRASET:
695 -               /* set read ahead for block device */
696 -               if (!capable(CAP_SYS_ADMIN))
697 -                       return -EACCES;
698 -
699 -               P_IOCTL("BLKRASET: %ld sectors for %s\n",
700 -                       (long) arg, kdevname(inode->i_rdev));
701 -
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;
707 -               break;
708 -
709 +       int ret = 0;
710 +       uchar heads = 128;
711 +       uchar sectors = 128;
712 +       ulong start = 0;
713 +       uint cylinders;
714 +
715 +       while ( heads * sectors > lv_ptr->lv_size) {
716 +               heads >>= 1;
717 +               sectors >>= 1;
718 +       }
719 +       cylinders = lv_ptr->lv_size / heads / sectors;
720  
721 -       case BLKRAGET:
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))
725 -                       return -EFAULT;
726 -               break;
727 +       switch (what) {
728 +               case 0:
729 +               {
730 +                       struct hd_geometry *hd = (struct hd_geometry *) a;
731  
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))
736 +                               return -EFAULT;
737 +                       break;
738 +               }
739  
740 -       case HDIO_GETGEO:
741 -               /* get disk geometry */
742 -               P_IOCTL("%s -- lvm_blk_ioctl -- HDIO_GETGEO\n", lvm_name);
743 -               if (hd == NULL)
744 -                       return -EINVAL;
745 +#ifdef HDIO_GETGEO_BIG
746 +               case 1:
747                 {
748 -                       unsigned char heads = 64;
749 -                       unsigned char sectors = 32;
750 -                       long start = 0;
751 -                       short cylinders =
752 -                           lv_ptr->lv_size / heads / sectors;
753 -
754 -                       if (copy_to_user((char *) &hd->heads, &heads,
755 -                                        sizeof(heads)) != 0 ||
756 -                           copy_to_user((char *) &hd->sectors, &sectors,
757 -                                        sizeof(sectors)) != 0 ||
758 -                           copy_to_user((short *) &hd->cylinders,
759 -                                        &cylinders,
760 -                                        sizeof(cylinders)) != 0
761 -                           || copy_to_user((long *) &hd->start, &start,
762 -                                           sizeof(start)) != 0)
763 -                               return -EFAULT;
764 +                       struct hd_big_geometry *hd =
765 +                               (struct hd_big_geometry *) a;
766  
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))
773 +                               return -EFAULT;
774 +                       break;
775                 }
776 -               break;
777 -
778 +#endif
779  
780 -       case LV_SET_ACCESS:
781 -               /* set access flags of a logical volume */
782 -               if (!capable(CAP_SYS_ADMIN))
783 -                       return -EACCES;
784 -               lv_ptr->lv_access = (ulong) arg;
785 -               if (lv_ptr->lv_access & LV_WRITE)
786 -                       set_device_ro(lv_ptr->lv_dev, 0);
787 -               else
788 -                       set_device_ro(lv_ptr->lv_dev, 1);
789 -               break;
790 +       }
791  
792 +       P_IOCTL("%s -- lvm_blk_ioctl -- cylinders: %d\n",
793 +               lvm_name, cylinders);
794 +       return ret;
795 +}
796  
797 -       case LV_SET_STATUS:
798 -               /* set status flags of a logical volume */
799 -               if (!capable(CAP_SYS_ADMIN))
800 -                       return -EACCES;
801 -               if (!((ulong) arg & LV_ACTIVE) && lv_ptr->lv_open > 1)
802 -                       return -EPERM;
803 -               lv_ptr->lv_status = (ulong) arg;
804 -               break;
805  
806 -       case LV_BMAP:
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)
810 -                       return -EPERM;
811 -
812 -               return lvm_user_bmap(inode, (struct lv_bmap *) arg);
813 -
814 -       case LV_SET_ALLOCATION:
815 -               /* set allocation flags of a logical volume */
816 -               if (!capable(CAP_SYS_ADMIN))
817 -                       return -EACCES;
818 -               lv_ptr->lv_allocation = (ulong) arg;
819 -               break;
820 +/*
821 + * block device i/o-control routine
822 + */
823 +static int lvm_blk_ioctl(struct inode *inode, struct file *file,
824 +                        uint cmd, ulong a)
825 +{
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;
831  
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));
837  
838 -       default:
839 -               printk(KERN_WARNING
840 -                      "%s -- lvm_blk_ioctl: unknown command 0x%x\n",
841 -                      lvm_name, command);
842 -               return -EINVAL;
843 +       switch (cmd) {
844 +               case BLKRASET:
845 +                       /* set read ahead for block device */
846 +                       ret = blk_ioctl(dev, cmd, a);
847 +                       if (ret)
848 +                               return ret;
849 +                       lv_ptr->lv_read_ahead = (long) a;
850 +                       LVM_CORRECT_READ_AHEAD(lv_ptr->lv_read_ahead);
851 +                       break;
852 +       
853 +               case HDIO_GETGEO:
854 +#ifdef HDIO_GETGEO_BIG
855 +               case HDIO_GETGEO_BIG:
856 +#endif
857 +                       /* get disk geometry */
858 +                       P_IOCTL("%s -- lvm_blk_ioctl -- HDIO_GETGEO\n",
859 +                               lvm_name);
860 +                       if (!a)
861 +                               return -EINVAL;
862 +
863 +                       switch (cmd) {
864 +                               case HDIO_GETGEO:
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);
869 +#endif
870 +                       }
871 +       
872 +               case LV_BMAP:
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)
876 +                               return -EPERM;
877 +       
878 +                       return lvm_user_bmap(inode, (struct lv_bmap *) arg);
879 +       
880 +               case LV_SET_ACCESS:
881 +                       /* set access flags of a logical volume */
882 +                       if (!capable(CAP_SYS_ADMIN)) return -EACCES;
883 +       
884 +                       down_write(&lv_ptr->lv_lock);
885 +                       lv_ptr->lv_access = (ulong) arg;
886 +                       up_write(&lv_ptr->lv_lock);
887 +       
888 +                       if ( lv_ptr->lv_access & LV_WRITE)
889 +                               set_device_ro(lv_ptr->lv_dev, 0);
890 +                       else
891 +                               set_device_ro(lv_ptr->lv_dev, 1);
892 +                       break;
893 +       
894 +       
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);
901 +                       break;
902 +       
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)
907 +                               return -EPERM;
908 +                       down_write(&lv_ptr->lv_lock);
909 +                       lv_ptr->lv_status = (ulong) arg;
910 +                       up_write(&lv_ptr->lv_lock);
911 +                       break;
912 +       
913 +               case LV_SNAPSHOT_USE_RATE:
914 +                       return lvm_get_snapshot_use_rate(lv_ptr, arg);
915 +       
916 +               default:
917 +                       /* Handle rest here */
918 +                       ret = blk_ioctl(dev, cmd, a);
919 +                       if (ret)
920 +                               printk(KERN_WARNING
921 +                                      "%s -- lvm_blk_ioctl: unknown "
922 +                                      "cmd 0x%x\n",
923 +                                      lvm_name, cmd);
924 +                       return ret;
925         }
926  
927         return 0;
928 -}                              /* lvm_blk_ioctl() */
929 +} /* lvm_blk_ioctl() */
930  
931  
932  /*
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));
936  
937 -       if (lv_ptr->lv_open == 1)
938 -               vg_ptr->lv_open--;
939 +       if (lv_ptr->lv_open == 1) vg_ptr->lv_open--;
940         lv_ptr->lv_open--;
941  
942         MOD_DEC_USE_COUNT;
943  
944         return 0;
945 -}                              /* lvm_blk_close() */
946 +} /* lvm_blk_close() */
947  
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)
950  {
951         lv_snapshot_use_rate_req_t lv_rate_req;
952  
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);
957                 return -EPERM;
958 +       }
959 +       up_read(&lv->lv_lock);
960  
961         if (copy_from_user(&lv_rate_req, arg, sizeof(lv_rate_req)))
962                 return -EFAULT;
963 @@ -1090,10 +1086,17 @@
964  
965         switch (lv_rate_req.block) {
966         case 0:
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);
978 +               }
979 +               up_read(&lv->lv_lock);
980                 break;
981  
982         case O_NONBLOCK:
983 @@ -1102,7 +1105,9 @@
984         default:
985                 return -EINVAL;
986         }
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);
990  
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))
995                 return -EFAULT;
996  
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);
1003         bh.b_end_io = NULL;
1004 -       if ((err = lvm_map(&bh, READ)) < 0) {
1005 +       if ((err = lvm_map(&bh, READ)) < 0)  {
1006                 printk("lvm map failed: %d\n", err);
1007                 return -EINVAL;
1008         }
1009  
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) ?
1014 +               -EFAULT : 0;
1015  }
1016  
1017  
1018 @@ -1139,8 +1144,7 @@
1019   * (see init_module/lvm_init)
1020   */
1021  static void __remap_snapshot(kdev_t rdev, ulong rsector,
1022 -                            ulong pe_start, lv_t * lv, vg_t * vg)
1023 -{
1024 +                                   ulong pe_start, lv_t *lv, vg_t *vg) {
1025  
1026         /* copy a chunk from the origin to a snapshot device */
1027         down_write(&lv->lv_lock);
1028 @@ -1155,8 +1159,7 @@
1029  }
1030  
1031  static inline void _remap_snapshot(kdev_t rdev, ulong rsector,
1032 -                                  ulong pe_start, lv_t * lv, vg_t * vg)
1033 -{
1034 +                                  ulong pe_start, lv_t *lv, vg_t *vg) {
1035         int r;
1036  
1037         /* check to see if this chunk is already in the snapshot */
1038 @@ -1173,8 +1176,7 @@
1039  /*
1040   * extents destined for a pe that is on the move should be deferred
1041   */
1042 -static inline int _should_defer(kdev_t pv, ulong sector, uint32_t pe_size)
1043 -{
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 @@
1049                 goto bad;
1050         }
1051  
1052 -       if ((rw == WRITE || rw == WRITEA) && !(lv->lv_access & LV_WRITE)) {
1053 +       if ((rw == WRITE || rw == WRITEA) &&
1054 +           !(lv->lv_access & LV_WRITE)) {
1055                 printk(KERN_CRIT
1056                        "%s - lvm_map: ll_rw_blk write for readonly LV %s\n",
1057                        lvm_name, lv->lv_name);
1058                 goto bad;
1059         }
1060  
1061 -       P_MAP
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",
1065 +             lvm_name, minor,
1066 +             kdevname(bh->b_rdev),
1067 +             rsector_org, size);
1068  
1069         if (rsector_org + size > lv->lv_size) {
1070                 printk(KERN_ALERT
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);
1076                 goto bad;
1077         }
1078  
1079  
1080 -       if (lv->lv_stripes < 2) {       /* linear mapping */
1081 +       if (lv->lv_stripes < 2) { /* linear mapping */
1082                 /* get the index */
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;
1089  
1090                 P_MAP("lv_current_pe[%ld].pe: %d  rdev: %s  rsector:%ld\n",
1091 @@ -1259,23 +1263,22 @@
1092  
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;
1113  
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,
1118 -                     stripe_index);
1119 +                     index, lv->lv_current_pe[index].pe, kdevname(rdev_map),
1120 +                     rsector_map, stripe_length, stripe_index);
1121         }
1122  
1123         /*
1124 @@ -1284,8 +1287,8 @@
1125          * we need to queue this request, because this is in the fast path.
1126          */
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)) {
1132  
1133                         up_read(&lv->lv_lock);
1134                         return 0;
1135 @@ -1296,14 +1299,15 @@
1136                 lv->lv_current_pe[index].reads++;       /* statistic */
1137  
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)))
1141                 goto out;
1142  
1143 -       if (lv->lv_access & LV_SNAPSHOT) {      /* remap snapshot */
1144 -               if (lvm_snapshot_remap_block
1145 -                   (&rdev_map, &rsector_map, pe_start, lv) < 0)
1146 -                               goto bad;
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)
1151 +                       goto bad;
1152 +
1153 +       } else if (rw == WRITE || rw == WRITEA) { /* snapshot origin */
1154                 lv_t *snap;
1155  
1156                 /* start with first snapshot and loop through all of
1157 @@ -1317,21 +1321,22 @@
1158                         /* Serializes the COW with the accesses to the
1159                            snapshot device */
1160                         _remap_snapshot(rdev_map, rsector_map,
1161 -                                       pe_start, snap, vg_this);
1162 +                                        pe_start, snap, vg_this);
1163                 }
1164         }
1165  
1166 -      out:
1167 + out:
1168         bh->b_rdev = rdev_map;
1169         bh->b_rsector = rsector_map;
1170         up_read(&lv->lv_lock);
1171         return 1;
1172  
1173 -      bad:
1174 -       if (bh->b_end_io) buffer_IO_error(bh);
1175 + bad:
1176 +       if (bh->b_end_io)
1177 +       buffer_IO_error(bh);
1178         up_read(&lv->lv_lock);
1179         return -1;
1180 -}                              /* lvm_map() */
1181 +} /* lvm_map() */
1182  
1183  
1184  /*
1185 @@ -1363,8 +1368,9 @@
1186  /*
1187   * make request function
1188   */
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,
1192 +                              int rw,
1193 +                              struct buffer_head *bh)
1194  {
1195         return (lvm_map(bh, rw) <= 0) ? 0 : 1;
1196  }
1197 @@ -1380,7 +1386,7 @@
1198   */
1199  static int lvm_do_lock_lvm(void)
1200  {
1201 -      lock_try_again:
1202 +lock_try_again:
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);
1209         return 0;
1210 -}                              /* lvm_do_lock_lvm */
1211 +} /* lvm_do_lock_lvm */
1212  
1213  
1214  /*
1215   * character device support function lock/unlock physical extend
1216   */
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)
1219  {
1220         pe_lock_req_t new_lock;
1221         struct buffer_head *bh;
1222         uint p;
1223  
1224 -       if (vg_ptr == NULL)
1225 -               return -ENXIO;
1226 +       if (vg_ptr == NULL) return -ENXIO;
1227         if (copy_from_user(&new_lock, arg, sizeof(new_lock)) != 0)
1228                 return -EFAULT;
1229  
1230 @@ -1422,8 +1427,7 @@
1231                             new_lock.data.pv_dev == vg_ptr->pv[p]->pv_dev)
1232                                 break;
1233                 }
1234 -               if (p == vg_ptr->pv_max)
1235 -                       return -ENXIO;
1236 +               if (p == vg_ptr->pv_max) return -ENXIO;
1237  
1238                 /*
1239                  * this sync releaves memory pressure to lessen the
1240 @@ -1474,20 +1478,24 @@
1241  /*
1242   * character device support function logical extend remap
1243   */
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)
1246  {
1247         uint l, le;
1248         lv_t *lv_ptr;
1249  
1250 -       if (vg_ptr == NULL)
1251 -               return -ENXIO;
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)
1256 +               return -EFAULT;
1257  
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) {
1262 +
1263 +               if (!lv_ptr)
1264 +                       continue;
1265 +
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;
1275 -
1276                                         __update_hardsectsize(lv_ptr);
1277 +                                       up_write(&lv_ptr->lv_lock);
1278                                         return 0;
1279                                 }
1280                         }
1281 +                       up_write(&lv_ptr->lv_lock);
1282                         return -EINVAL;
1283                 }
1284         }
1285         return -ENXIO;
1286 -}                              /* lvm_do_le_remap() */
1287 +} /* lvm_do_le_remap() */
1288  
1289  
1290  /*
1291 @@ -1520,7 +1529,7 @@
1292         vg_t *vg_ptr;
1293         lv_t **snap_lv_ptr;
1294  
1295 -       if ((vg_ptr = kmalloc(sizeof(vg_t), GFP_KERNEL)) == NULL) {
1296 +       if ((vg_ptr = kmalloc(sizeof(vg_t),GFP_KERNEL)) == NULL) {
1297                 printk(KERN_CRIT
1298                        "%s -- VG_CREATE: kmalloc error VG at line %d\n",
1299                        lvm_name, __LINE__);
1300 @@ -1528,9 +1537,8 @@
1301         }
1302         /* get the volume group structure */
1303         if (copy_from_user(vg_ptr, arg, sizeof(vg_t)) != 0) {
1304 -               P_IOCTL
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));
1309                 kfree(vg_ptr);
1310                 return -EFAULT;
1311         }
1312 @@ -1539,6 +1547,10 @@
1313         if (minor == -1)
1314                 minor = vg_ptr->vg_number;
1315  
1316 +       /* check limits */
1317 +       if (minor >= ABS_MAX_VG)
1318 +               return -EFAULT;
1319 +
1320         /* Validate it */
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 @@
1324  
1325         if (vg_ptr->lv_max > ABS_MAX_LV) {
1326                 printk(KERN_WARNING
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);
1330                 kfree(vg_ptr);
1331                 return -EPERM;
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);
1336 -                       if (ret != 0) {
1337 +                       if ( ret != 0) {
1338                                 lvm_do_vg_remove(minor);
1339                                 return ret;
1340                         }
1341 @@ -1586,7 +1598,7 @@
1342         }
1343  
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) {
1347                 printk(KERN_CRIT
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) {
1354 -                               P_IOCTL
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);
1360                                 return -EFAULT;
1361                         }
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;
1366                                 ls++;
1367 @@ -1648,26 +1659,24 @@
1368         vg_ptr->vg_status |= VG_ACTIVE;
1369  
1370         return 0;
1371 -}                              /* lvm_do_vg_create() */
1372 +} /* lvm_do_vg_create() */
1373  
1374  
1375  /*
1376   * character device support function VGDA extend
1377   */
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)
1380  {
1381         int ret = 0;
1382         uint p;
1383         pv_t *pv_ptr;
1384  
1385 -       if (vg_ptr == NULL)
1386 -               return -ENXIO;
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);
1393 -                               if (ret != 0)
1394 -                                       return ret;
1395 +                               if ( ret != 0) return ret;
1396                                 pv_ptr = vg_ptr->pv[p];
1397                                 vg_ptr->pe_total += pv_ptr->pe_total;
1398                                 return 0;
1399 @@ -1675,28 +1684,26 @@
1400                 }
1401         }
1402         return -EPERM;
1403 -}                              /* lvm_do_vg_extend() */
1404 +} /* lvm_do_vg_extend() */
1405  
1406  
1407  /*
1408   * character device support function VGDA reduce
1409   */
1410 -static int lvm_do_vg_reduce(vg_t * vg_ptr, void *arg)
1411 -{
1412 +static int lvm_do_vg_reduce(vg_t *vg_ptr, void *arg) {
1413         uint p;
1414         pv_t *pv_ptr;
1415  
1416 -       if (vg_ptr == NULL)
1417 -               return -ENXIO;
1418 +       if (vg_ptr == NULL) return -ENXIO;
1419         if (copy_from_user(pv_name, arg, sizeof(pv_name)) != 0)
1420                 return -EFAULT;
1421  
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)
1427 -                               return -EPERM;
1428 +                   strcmp(pv_ptr->pv_name,
1429 +                              pv_name) == 0) {
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 @@
1435                 }
1436         }
1437         return -ENXIO;
1438 -}                              /* lvm_do_vg_reduce */
1439 +} /* lvm_do_vg_reduce */
1440  
1441  
1442  /*
1443   * character device support function VG rename
1444   */
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)
1447  {
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,};
1453         char *ptr = NULL;
1454         lv_t *lv_ptr = NULL;
1455         pv_t *pv_ptr = NULL;
1456  
1457         /* If the VG doesn't exist in the kernel then just exit */
1458 -       if (!vg_ptr)
1459 -               return 0;
1460 +       if (!vg_ptr) return 0;
1461  
1462         if (copy_from_user(vg_name, arg, sizeof(vg_name)) != 0)
1463                 return -EFAULT;
1464  
1465         lvm_fs_remove_vg(vg_ptr);
1466  
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)
1470 -                       continue;
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++)
1474 +       {
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, '/');
1479 -               if (ptr == NULL)
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);
1491         }
1492 -       for (p = 0; p < vg_ptr->pv_max; p++) {
1493 -               if ((pv_ptr = vg_ptr->pv[p]) == NULL)
1494 -                       continue;
1495 +       for ( p = 0; p < vg_ptr->pv_max; p++)
1496 +       {
1497 +               if ( (pv_ptr = vg_ptr->pv[p]) == NULL) continue;
1498                 strncpy(pv_ptr->vg_name, vg_name, NAME_LEN);
1499         }
1500  
1501         lvm_fs_create_vg(vg_ptr);
1502  
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];
1506 +
1507 +               if (pv_ptr)
1508 +                       lvm_fs_create_pv(vg_ptr, pv_ptr);
1509 +       }
1510 +
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];
1514 +
1515 +               if (!lv_ptr)
1516 +                       continue;
1517 +
1518 +               lvm_gendisk.part[MINOR(lv_ptr->lv_dev)].de =
1519 +                       lvm_fs_create_lv(vg_ptr, lv_ptr);
1520 +       }
1521 +
1522         return 0;
1523 -}                              /* lvm_do_vg_rename */
1524 +} /* lvm_do_vg_rename */
1525  
1526  
1527  /*
1528 @@ -1766,8 +1792,7 @@
1529         vg_t *vg_ptr = vg[VG_CHR(minor)];
1530         pv_t *pv_ptr;
1531  
1532 -       if (vg_ptr == NULL)
1533 -               return -ENXIO;
1534 +       if (vg_ptr == NULL) return -ENXIO;
1535  
1536  #ifdef LVM_TOTAL_RESET
1537         if (vg_ptr->lv_open > 0 && lvm_reset_spindown == 0)
1538 @@ -1818,18 +1843,20 @@
1539         MOD_DEC_USE_COUNT;
1540  
1541         return 0;
1542 -}                              /* lvm_do_vg_remove() */
1543 +} /* lvm_do_vg_remove() */
1544  
1545  
1546  /*
1547   * character device support function physical volume create
1548   */
1549 -static int lvm_do_pv_create(pv_t * pvp, vg_t * vg_ptr, ulong p)
1550 -{
1551 +static int lvm_do_pv_create(pv_t *pvp, vg_t *vg_ptr, ulong p) {
1552         pv_t *pv;
1553         int err;
1554  
1555 -       pv = kmalloc(sizeof(pv_t), GFP_KERNEL);
1556 +       if (!vg_ptr)
1557 +               return -ENXIO;
1558 +
1559 +       pv = kmalloc(sizeof(pv_t),GFP_KERNEL);
1560         if (pv == NULL) {
1561                 printk(KERN_CRIT
1562                        "%s -- PV_CREATE: kmalloc error PV at line %d\n",
1563 @@ -1840,9 +1867,8 @@
1564         memset(pv, 0, sizeof(*pv));
1565  
1566         if (copy_from_user(pv, pvp, sizeof(pv_t)) != 0) {
1567 -               P_IOCTL
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));
1572                 kfree(pv);
1573                 return -EFAULT;
1574         }
1575 @@ -1863,14 +1889,13 @@
1576  
1577         vg_ptr->pv[p] = pv;
1578         return 0;
1579 -}                              /* lvm_do_pv_create() */
1580 +} /* lvm_do_pv_create() */
1581  
1582  
1583  /*
1584   * character device support function physical volume remove
1585   */
1586 -static int lvm_do_pv_remove(vg_t * vg_ptr, ulong p)
1587 -{
1588 +static int lvm_do_pv_remove(vg_t *vg_ptr, ulong p) {
1589         pv_t *pv = vg_ptr->pv[p];
1590  
1591         lvm_fs_remove_pv(vg_ptr, pv);
1592 @@ -1888,7 +1913,7 @@
1593  }
1594  
1595  
1596 -static void __update_hardsectsize(lv_t * lv)
1597 +static void __update_hardsectsize(lv_t *lv)
1598  {
1599         int max_hardsectsize = 0, hardsectsize = 0;
1600         int p;
1601 @@ -1900,10 +1925,9 @@
1602                         if (max_hardsectsize == 0)
1603                                 max_hardsectsize = hardsectsize;
1604                         else if (hardsectsize != max_hardsectsize) {
1605 -                               P_DEV
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);
1612                                 break;
1613                         }
1614                 }
1615 @@ -1913,14 +1937,12 @@
1616         if (hardsectsize != max_hardsectsize) {
1617                 int le;
1618                 for (le = 0; le < lv->lv_allocated_le; le++) {
1619 -                       hardsectsize =
1620 -                           lvm_sectsize(lv->lv_current_pe[le].dev);
1621 +                       hardsectsize = lvm_sectsize(lv->lv_current_pe[le].dev);
1622                         if (hardsectsize > max_hardsectsize) {
1623 -                               P_DEV
1624 -                                   ("%s LE[%d] (%s) blocksize %d not %d\n",
1625 -                                    lv->lv_name, le,
1626 -                                    kdevname(lv->lv_current_pe[le].dev),
1627 -                                    hardsectsize, max_hardsectsize);
1628 +                               P_DEV("%s LE[%d] (%s) blocksize %d not %d\n",
1629 +                                     lv->lv_name, le,
1630 +                                     kdevname(lv->lv_current_pe[le].dev),
1631 +                                     hardsectsize, max_hardsectsize);
1632                                 max_hardsectsize = hardsectsize;
1633                         }
1634                 }
1635 @@ -1930,9 +1952,7 @@
1636                     (lv->lv_status & LV_ACTIVE)) {
1637                         int e;
1638                         for (e = 0; e < lv->lv_remap_end; e++) {
1639 -                               hardsectsize =
1640 -                                   lvm_sectsize(lv->lv_block_exception[e].
1641 -                                                rdev_new);
1642 +                               hardsectsize = lvm_sectsize(lv->lv_block_exception[e].rdev_new);
1643                                 if (hardsectsize > max_hardsectsize)
1644                                         max_hardsectsize = hardsectsize;
1645                         }
1646 @@ -1949,7 +1969,7 @@
1647  /*
1648   * character device support function logical volume create
1649   */
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)
1652  {
1653         int e, ret, l, le, l_new, p, size, activate = 1;
1654         ulong lv_status_save;
1655 @@ -1977,18 +1997,14 @@
1656         else {
1657                 for (l = 0; l < vg_ptr->lv_max; l++) {
1658                         if (vg_ptr->lv[l] == NULL)
1659 -                               if (l_new == -1)
1660 -                                       l_new = l;
1661 +                               if (l_new == -1) l_new = l;
1662                 }
1663         }
1664 -       if (l_new == -1)
1665 -               return -EPERM;
1666 -       else
1667 -               l = l_new;
1668 +       if (l_new == -1) return -EPERM;
1669 +       else             l = l_new;
1670  
1671 -       if ((lv_ptr = kmalloc(sizeof(lv_t), GFP_KERNEL)) == NULL) {;
1672 -               printk(KERN_CRIT
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__);
1677                 return -ENOMEM;
1678         }
1679 @@ -2020,7 +2036,8 @@
1680                 if ((lv_ptr->lv_current_pe = vmalloc(size)) == NULL) {
1681                         printk(KERN_CRIT
1682                                "%s -- LV_CREATE: vmalloc error LV_CURRENT_PE of %d Byte "
1683 -                              "at line %d\n", lvm_name, size, __LINE__);
1684 +                              "at line %d\n",
1685 +                              lvm_name, size, __LINE__);
1686                         P_KFREE("%s -- kfree %d\n", lvm_name, __LINE__);
1687                         kfree(lv_ptr);
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) {
1693 -                               size =
1694 -                                   lv_ptr->lv_remap_end *
1695 -                                   sizeof(lv_block_exception_t);
1696 +                               size = lv_ptr->lv_remap_end * sizeof(lv_block_exception_t);
1697  
1698                                 if (!size) {
1699                                         printk(KERN_WARNING
1700 @@ -2061,33 +2076,29 @@
1701                                         return -EINVAL;
1702                                 }
1703  
1704 -                               if (
1705 -                                   (lv_ptr->lv_block_exception =
1706 -                                    vmalloc(size)) == NULL) {
1707 +                               if ((lv_ptr->lv_block_exception = vmalloc(size)) == NULL) {
1708                                         printk(KERN_CRIT
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,
1715 +                                               __LINE__);
1716                                         kfree(lv_ptr);
1717                                         vg_ptr->lv[l] = NULL;
1718                                         return -ENOMEM;
1719                                 }
1720 -                               if (copy_from_user
1721 -                                   (lv_ptr->lv_block_exception, lvbe,
1722 -                                    size)) {
1723 +                               if (copy_from_user(lv_ptr->lv_block_exception, lvbe, size)) {
1724                                         vfree(lv_ptr->lv_block_exception);
1725                                         kfree(lv_ptr);
1726                                         vg_ptr->lv[l] = NULL;
1727                                         return -EFAULT;
1728                                 }
1729  
1730 -                               if (lv_ptr->lv_block_exception[0].
1731 -                                   rsector_org ==
1732 -                                   LVM_SNAPSHOT_DROPPED_SECTOR) {
1733 +                               if(lv_ptr->lv_block_exception[0].rsector_org ==
1734 +                                  LVM_SNAPSHOT_DROPPED_SECTOR)
1735 +                               {
1736                                         printk(KERN_WARNING
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",
1739                                                lvm_name);
1740                                         activate = 0;
1741                                 }
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->
1752 -                                   lv_allocated_le;
1753 -                               lv_ptr->lv_current_le =
1754 -                                   lv_ptr->lv_snapshot_org->lv_current_le;
1755 -                               lv_ptr->lv_size =
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;
1768  
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;
1773  
1774 -                               if ((ret = lvm_snapshot_alloc(lv_ptr)) !=
1775 -                                   0) {
1776 +                               if ((ret = lvm_snapshot_alloc(lv_ptr)) != 0)
1777 +                               {
1778                                         vfree(lv_ptr->lv_block_exception);
1779                                         kfree(lv_ptr);
1780                                         vg_ptr->lv[l] = NULL;
1781                                         return ret;
1782                                 }
1783 -                               for (e = 0; e < lv_ptr->lv_remap_ptr; e++)
1784 -                                       lvm_hash_link(lv_ptr->
1785 -                                                     lv_block_exception +
1786 -                                                     e,
1787 -                                                     lv_ptr->
1788 -                                                     lv_block_exception
1789 -                                                     [e].rdev_org,
1790 -                                                     lv_ptr->
1791 -                                                     lv_block_exception
1792 -                                                     [e].rsector_org,
1793 -                                                     lv_ptr);
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)) {
1803                                         kfree(lv_ptr);
1804                                         vg_ptr->lv[l] = NULL;
1805                                         return -EINVAL;
1806                                 }
1807 -                               init_waitqueue_head(&lv_ptr->
1808 -                                                   lv_snapshot_wait);
1809 +                               init_waitqueue_head(&lv_ptr->lv_snapshot_wait);
1810                         } else {
1811                                 kfree(lv_ptr);
1812                                 vg_ptr->lv[l] = NULL;
1813 @@ -2159,7 +2152,7 @@
1814                         vg_ptr->lv[l] = NULL;
1815                         return -EINVAL;
1816                 }
1817 -       }                       /* if ( vg[VG_CHR(minor)]->lv[l]->lv_access & LV_SNAPSHOT) */
1818 +       } /* if ( vg[VG_CHR(minor)]->lv[l]->lv_access & LV_SNAPSHOT) */
1819  
1820         lv_ptr = vg_ptr->lv[l];
1821         lvm_gendisk.part[MINOR(lv_ptr->lv_dev)].start_sect = 0;
1822 @@ -2187,24 +2180,23 @@
1823  
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 */
1828  
1829  
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);
1837         }
1838  
1839         /* activate the logical volume */
1840 -       if (activate)
1841 +       if(activate)
1842                 lv_ptr->lv_status |= LV_ACTIVE;
1843         else
1844                 lv_ptr->lv_status &= ~LV_ACTIVE;
1845  
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);
1849         else
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);
1854         return 0;
1855 -}                              /* lvm_do_lv_create() */
1856 +} /* lvm_do_lv_create() */
1857  
1858  
1859  /*
1860 @@ -2230,6 +2222,9 @@
1861         vg_t *vg_ptr = vg[VG_CHR(minor)];
1862         lv_t *lv_ptr;
1863  
1864 +       if (!vg_ptr)
1865 +               return -ENXIO;
1866 +
1867         if (l == -1) {
1868                 for (l = 0; l < vg_ptr->lv_max; l++) {
1869                         if (vg_ptr->lv[l] != NULL &&
1870 @@ -2238,8 +2233,7 @@
1871                         }
1872                 }
1873         }
1874 -       if (l == vg_ptr->lv_max)
1875 -               return -ENXIO;
1876 +       if (l == vg_ptr->lv_max) return -ENXIO;
1877  
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.
1883                  */
1884 -               lv_t *org = lv_ptr->lv_snapshot_org;
1885 +               lv_t * org = lv_ptr->lv_snapshot_org;
1886                 down_write(&org->lv_lock);
1887  
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;
1897  
1898         /* correct the PE count in PVs if this is not a snapshot
1899 -          logical volume */
1900 +           logical volume */
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;
1906         vg_ptr->lv_cur--;
1907         return 0;
1908 -}                              /* lvm_do_lv_remove() */
1909 +} /* lvm_do_lv_remove() */
1910  
1911  
1912  /*
1913   * logical volume extend / reduce
1914   */
1915 -static int __extend_reduce_snapshot(vg_t * vg_ptr, lv_t * old_lv,
1916 -                                   lv_t * new_lv)
1917 -{
1918 +static int __extend_reduce_snapshot(vg_t *vg_ptr, lv_t *old_lv, lv_t *new_lv) {
1919         ulong size;
1920         lv_block_exception_t *lvbe;
1921  
1922 @@ -2366,8 +2357,7 @@
1923         return 0;
1924  }
1925  
1926 -static int __extend_reduce(vg_t * vg_ptr, lv_t * old_lv, lv_t * new_lv)
1927 -{
1928 +static int __extend_reduce(vg_t *vg_ptr, lv_t *old_lv, lv_t *new_lv) {
1929         ulong size, l, p, end;
1930         pe_t *pe;
1931  
1932 @@ -2383,7 +2373,7 @@
1933  
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);
1939                 vfree(pe);
1940                 return -EFAULT;
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++;
1948                                 break;
1949                         }
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;
1956  
1957                         new_lv->lv_current_pe[l].writes +=
1958 -                           old_lv->lv_current_pe[l].writes;
1959 +                               old_lv->lv_current_pe[l].writes;
1960                 }
1961  
1962         } else {                /* striped logical volume */
1963 -               uint i, j, source, dest, end, old_stripe_size,
1964 -                   new_stripe_size;
1965 +               uint i, j, source, dest, end, old_stripe_size, new_stripe_size;
1966  
1967 -               old_stripe_size =
1968 -                   old_lv->lv_allocated_le / old_lv->lv_stripes;
1969 -               new_stripe_size =
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);
1974  
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 +
1979 -                                                         j].reads;
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 +
1983 -                                                         j].writes;
1984 +                                   old_lv->lv_current_pe[source + j].writes;
1985                         }
1986                         source += old_stripe_size;
1987                         dest += new_stripe_size;
1988 @@ -2453,7 +2438,7 @@
1989         return 0;
1990  }
1991  
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)
1994  {
1995         int r;
1996         ulong l, e, size;
1997 @@ -2461,12 +2446,15 @@
1998         lv_t *old_lv;
1999         pe_t *pe;
2000  
2001 +       if (!vg_ptr)
2002 +               return -ENXIO;
2003 +
2004         if ((pe = new_lv->lv_current_pe) == NULL)
2005                 return -EINVAL;
2006  
2007         for (l = 0; l < vg_ptr->lv_max; l++)
2008 -               if (vg_ptr->lv[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))
2011 +                       break;
2012  
2013         if (l == vg_ptr->lv_max)
2014                 return -ENXIO;
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)
2019 -                       r =
2020 -                           __extend_reduce_snapshot(vg_ptr, old_lv,
2021 -                                                    new_lv);
2022 +                       r = __extend_reduce_snapshot(vg_ptr, old_lv, new_lv);
2023                 else
2024                         r = -EPERM;
2025  
2026         } else
2027                 r = __extend_reduce(vg_ptr, old_lv, new_lv);
2028  
2029 -       if (r)
2030 +       if(r)
2031                 return r;
2032  
2033         /* copy relevent fields */
2034         down_write(&old_lv->lv_lock);
2035  
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;
2056  
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].
2060 -                                     rdev_org,
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,
2065 +                                     new_lv);
2066  
2067         } else {
2068  
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 =
2073 -                   old_lv->lv_size;
2074 +                       old_lv->lv_size;
2075                 lvm_size[MINOR(old_lv->lv_dev)] = old_lv->lv_size >> 1;
2076  
2077                 if (old_lv->lv_access & LV_SNAPSHOT_ORG) {
2078                         lv_t *snap;
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;
2094  
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);
2104                         }
2105 @@ -2554,13 +2537,13 @@
2106         up_write(&old_lv->lv_lock);
2107  
2108         return 0;
2109 -}                              /* lvm_do_lv_extend_reduce() */
2110 +} /* lvm_do_lv_extend_reduce() */
2111  
2112  
2113  /*
2114   * character device support function logical volume status by name
2115   */
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)
2118  {
2119         uint l;
2120         lv_status_byname_req_t lv_status_byname_req;
2121 @@ -2568,206 +2551,181 @@
2122         void *saved_ptr2;
2123         lv_t *lv_ptr;
2124  
2125 -       if (vg_ptr == NULL)
2126 -               return -ENXIO;
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)
2130                 return -EFAULT;
2131  
2132 -       if (lv_status_byname_req.lv == NULL)
2133 -               return -EINVAL;
2134 +       if (lv_status_byname_req.lv == NULL) return -EINVAL;
2135  
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
2142 -                           (&saved_ptr1,
2143 -                            &lv_status_byname_req.lv->lv_current_pe,
2144 -                            sizeof(void *)) != 0)
2145 -                               return -EFAULT;
2146 -                       if (copy_from_user
2147 -                           (&saved_ptr2,
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)
2152                                 return -EFAULT;
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)
2156 +                               return -EFAULT;
2157 +                       if (copy_to_user(lv_status_byname_req.lv,
2158 +                                        lv_ptr,
2159 +                                        sizeof(lv_t)) != 0)
2160                                 return -EFAULT;
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)
2167                                         return -EFAULT;
2168                         }
2169                         /* Restore usermode pointers */
2170 -                       if (copy_to_user
2171 -                           (&lv_status_byname_req.lv->lv_current_pe,
2172 -                            &saved_ptr1, sizeof(void *)) != 0)
2173 -                               return -EFAULT;
2174 +                       if (copy_to_user(&lv_status_byname_req.lv->lv_current_pe, &saved_ptr1, sizeof(void*)) != 0)
2175 +                               return -EFAULT;
2176                         return 0;
2177                 }
2178         }
2179         return -ENXIO;
2180 -}                              /* lvm_do_lv_status_byname() */
2181 +} /* lvm_do_lv_status_byname() */
2182  
2183  
2184  /*
2185   * character device support function logical volume status by index
2186   */
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)
2189  {
2190         lv_status_byindex_req_t lv_status_byindex_req;
2191         void *saved_ptr1;
2192         void *saved_ptr2;
2193         lv_t *lv_ptr;
2194  
2195 -       if (vg_ptr == NULL)
2196 -               return -ENXIO;
2197 +       if (vg_ptr == NULL) return -ENXIO;
2198         if (copy_from_user(&lv_status_byindex_req, arg,
2199                            sizeof(lv_status_byindex_req)) != 0)
2200                 return -EFAULT;
2201  
2202         if (lv_status_byindex_req.lv == NULL)
2203                 return -EINVAL;
2204 -       if (lv_status_byindex_req.lv_index < 0 ||
2205 -           lv_status_byindex_req.lv_index >= MAX_LV)
2206 -               return -EINVAL;
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)
2209                 return -ENXIO;
2210  
2211         /* Save usermode pointers */
2212 -       if (copy_from_user
2213 -           (&saved_ptr1, &lv_status_byindex_req.lv->lv_current_pe,
2214 -            sizeof(void *)) != 0)
2215 -               return -EFAULT;
2216 -       if (copy_from_user
2217 -           (&saved_ptr2, &lv_status_byindex_req.lv->lv_block_exception,
2218 -            sizeof(void *)) != 0)
2219 -               return -EFAULT;
2220 +       if (copy_from_user(&saved_ptr1, &lv_status_byindex_req.lv->lv_current_pe, sizeof(void*)) != 0)
2221 +               return -EFAULT;
2222 +       if (copy_from_user(&saved_ptr2, &lv_status_byindex_req.lv->lv_block_exception, sizeof(void*)) != 0)
2223 +               return -EFAULT;
2224  
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)
2228 +               return -EFAULT;
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)
2235 +                       return -EFAULT;
2236         }
2237  
2238         /* Restore usermode pointers */
2239 -       if (copy_to_user
2240 -           (&lv_status_byindex_req.lv->lv_current_pe, &saved_ptr1,
2241 -            sizeof(void *)) != 0)
2242 -               return -EFAULT;
2243 +       if (copy_to_user(&lv_status_byindex_req.lv->lv_current_pe, &saved_ptr1, sizeof(void *)) != 0)
2244 +               return -EFAULT;
2245  
2246         return 0;
2247 -}                              /* lvm_do_lv_status_byindex() */
2248 +} /* lvm_do_lv_status_byindex() */
2249  
2250  
2251  /*
2252   * character device support function logical volume status by device number
2253   */
2254 -static int lvm_do_lv_status_bydev(vg_t * vg_ptr, void *arg)
2255 -{
2256 +static int lvm_do_lv_status_bydev(vg_t * vg_ptr, void * arg) {
2257         int l;
2258         lv_status_bydev_req_t lv_status_bydev_req;
2259         void *saved_ptr1;
2260         void *saved_ptr2;
2261         lv_t *lv_ptr;
2262  
2263 -       if (vg_ptr == NULL)
2264 -               return -ENXIO;
2265 +       if (vg_ptr == NULL) return -ENXIO;
2266         if (copy_from_user(&lv_status_bydev_req, arg,
2267                            sizeof(lv_status_bydev_req)) != 0)
2268                 return -EFAULT;
2269  
2270 -       for (l = 0; l < vg_ptr->lv_max; l++) {
2271 -               if (vg_ptr->lv[l] == NULL)
2272 -                       continue;
2273 -               if (vg_ptr->lv[l]->lv_dev == lv_status_bydev_req.dev)
2274 -                       break;
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;
2278         }
2279  
2280 -       if (l == vg_ptr->lv_max)
2281 -               return -ENXIO;
2282 +       if ( l == vg_ptr->lv_max) return -ENXIO;
2283         lv_ptr = vg_ptr->lv[l];
2284  
2285         /* Save usermode pointers */
2286 -       if (copy_from_user
2287 -           (&saved_ptr1, &lv_status_bydev_req.lv->lv_current_pe,
2288 -            sizeof(void *)) != 0)
2289 -               return -EFAULT;
2290 -       if (copy_from_user
2291 -           (&saved_ptr2, &lv_status_bydev_req.lv->lv_block_exception,
2292 -            sizeof(void *)) != 0)
2293 -               return -EFAULT;
2294 +       if (copy_from_user(&saved_ptr1, &lv_status_bydev_req.lv->lv_current_pe, sizeof(void*)) != 0)
2295 +               return -EFAULT;
2296 +       if (copy_from_user(&saved_ptr2, &lv_status_bydev_req.lv->lv_block_exception, sizeof(void*)) != 0)
2297 +               return -EFAULT;
2298  
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)
2302 +               return -EFAULT;
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)
2309 +                       return -EFAULT;
2310         }
2311         /* Restore usermode pointers */
2312 -       if (copy_to_user
2313 -           (&lv_status_bydev_req.lv->lv_current_pe, &saved_ptr1,
2314 -            sizeof(void *)) != 0)
2315 -               return -EFAULT;
2316 +       if (copy_to_user(&lv_status_bydev_req.lv->lv_current_pe, &saved_ptr1, sizeof(void *)) != 0)
2317 +               return -EFAULT;
2318  
2319         return 0;
2320 -}                              /* lvm_do_lv_status_bydev() */
2321 +} /* lvm_do_lv_status_bydev() */
2322  
2323  
2324  /*
2325   * character device support function rename a logical volume
2326   */
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)
2329  {
2330         int l = 0;
2331         int ret = 0;
2332         lv_t *lv_ptr = NULL;
2333  
2334 -       for (l = 0; l < vg_ptr->lv_max; l++) {
2335 -               if ((lv_ptr = vg_ptr->lv[l]) == NULL)
2336 -                       continue;
2337 -               if (lv_ptr->lv_dev == lv->lv_dev) {
2338 +       if (!vg_ptr)
2339 +               return -ENXIO;
2340 +
2341 +       for (l = 0; l < vg_ptr->lv_max; l++)
2342 +       {
2343 +               if ( (lv_ptr = vg_ptr->lv[l]) == NULL) continue;
2344 +               if (lv_ptr->lv_dev == lv->lv_dev)
2345 +               {
2346                         lvm_fs_remove_lv(vg_ptr, lv_ptr);
2347 -                       strncpy(lv_ptr->lv_name, lv_req->lv_name,
2348 -                               NAME_LEN);
2349 +                       strncpy(lv_ptr->lv_name, lv_req->lv_name, NAME_LEN);
2350                         lvm_fs_create_lv(vg_ptr, lv_ptr);
2351                         break;
2352                 }
2353         }
2354 -       if (l == vg_ptr->lv_max)
2355 -               ret = -ENODEV;
2356 +       if (l == vg_ptr->lv_max) ret = -ENODEV;
2357  
2358         return ret;
2359 -}                              /* lvm_do_lv_rename */
2360 +} /* lvm_do_lv_rename */
2361  
2362  
2363  /*
2364   * character device support function physical volume change
2365   */
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)
2368  {
2369         uint p;
2370         pv_t *pv_ptr;
2371         struct block_device *bd;
2372  
2373 -       if (vg_ptr == NULL)
2374 -               return -ENXIO;
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)
2379 +               return -EFAULT;
2380  
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) {
2387  
2388                         bd = pv_ptr->bd;
2389                         if (copy_from_user(pv_ptr,
2390 @@ -2783,33 +2741,35 @@
2391                 }
2392         }
2393         return -ENXIO;
2394 -}                              /* lvm_do_pv_change() */
2395 +} /* lvm_do_pv_change() */
2396  
2397  /*
2398   * character device support function get physical volume status
2399   */
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)
2402  {
2403         uint p;
2404         pv_t *pv_ptr;
2405  
2406 -       if (vg_ptr == NULL)
2407 -               return -ENXIO;
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)
2412 +               return -EFAULT;
2413  
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)
2422 +                                        pv_ptr,
2423 +                                        sizeof(pv_t)) != 0)
2424                                 return -EFAULT;
2425                         return 0;
2426                 }
2427         }
2428         return -ENXIO;
2429 -}                              /* lvm_do_pv_status() */
2430 +} /* lvm_do_pv_status() */
2431  
2432  
2433  /*
2434 @@ -2851,15 +2811,13 @@
2435         hardsect_size[MAJOR_NR] = lvm_hardsectsizes;
2436  
2437         return;
2438 -}                              /* lvm_gen_init() */
2439 +} /* lvm_gen_init() */
2440  
2441  
2442  
2443  /* Must have down_write(_pe_lock) when we enqueue buffers */
2444 -static void _queue_io(struct buffer_head *bh, int rw)
2445 -{
2446 -       if (bh->b_reqnext)
2447 -               BUG();
2448 +static void _queue_io(struct buffer_head *bh, int rw) {
2449 +       if (bh->b_reqnext) BUG();
2450         bh->b_reqnext = _pe_requests;
2451         _pe_requests = bh;
2452  }
2453 @@ -2897,15 +2855,14 @@
2454  /*
2455   * we must open the pv's before we use them
2456   */
2457 -static int _open_pv(pv_t * pv)
2458 -{
2459 +static int _open_pv(pv_t *pv) {
2460         int err;
2461         struct block_device *bd;
2462  
2463         if (!(bd = bdget(kdev_t_to_nr(pv->pv_dev))))
2464                 return -ENOMEM;
2465  
2466 -       err = blkdev_get(bd, FMODE_READ | FMODE_WRITE, 0, BDEV_FILE);
2467 +       err = blkdev_get(bd, FMODE_READ|FMODE_WRITE, 0, BDEV_FILE);
2468         if (err)
2469                 return err;
2470  
2471 @@ -2913,8 +2870,7 @@
2472         return 0;
2473  }
2474  
2475 -static void _close_pv(pv_t * pv)
2476 -{
2477 +static void _close_pv(pv_t *pv) {
2478         if (pv) {
2479                 struct block_device *bdev = pv->bd;
2480                 pv->bd = NULL;
2481 @@ -2926,7 +2882,7 @@
2482  
2483  static unsigned long _sectors_to_k(unsigned long sect)
2484  {
2485 -       if (SECTOR_SIZE > 1024) {
2486 +       if(SECTOR_SIZE > 1024) {
2487                 return sect * (SECTOR_SIZE / 1024);
2488         }
2489  
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
2493 @@ -3,13 +3,14 @@
2494   * kernel/lvm.h
2495   * tools/lib/lvm.h
2496   *
2497 - * Copyright (C) 1997 - 2001  Heinz Mauelshagen, Sistina Software
2498 + * Copyright (C) 1997 - 2002  Heinz Mauelshagen, Sistina Software
2499   *
2500   * February-November 1997
2501   * May-July 1998
2502   * January-March,July,September,October,Dezember 1999
2503   * January,February,July,November 2000
2504   * January-March,June,July 2001
2505 + * May 2002
2506   *
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
2509 @@ -79,8 +80,8 @@
2510  #ifndef _LVM_H_INCLUDE
2511  #define _LVM_H_INCLUDE
2512  
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"
2517  
2518  #define        _LVM_KERNEL_H_VERSION   "LVM "LVM_RELEASE_NAME" ("LVM_RELEASE_DATE")"
2519  
2520 @@ -208,40 +209,35 @@
2521  /*
2522   * VGDA: default disk spaces and offsets
2523   *
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};
2527 - *
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.
2530 - *
2531 - *   offset               what                               size
2532 - *   ---------------      --------------------------------   ------------
2533 - *   0                    physical volume structure          pv->pv_on_disk.size
2534 - *                                                           (~500 byte)
2535 - *   pv->vg_on_disk.base  volume group structure             pv->vg_on_disk.size
2536 - *
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.
2541   *
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
2547   *
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
2551   *
2552 - *   End of disk -        first physical extent              default 4 megabyte
2553 + *   6K                namelist of physical volumes        128 byte each
2554 + *
2555 + *   6k + n * ~300byte n logical volume structures         ~300 byte each
2556 + *
2557 + *   + m * 4byte       m physical extent alloc. structs    4 byte each
2558 + *
2559 + *   End of disk -     first physical extent               typically 4 megabyte
2560   *   PE total *
2561   *   PE size
2562 - *   (rounded to 64k offset today)
2563   *
2564 - *   pv->pe_on_disk.base + pv->pe_on_disk.size == start of first physical extent
2565   *
2566   */
2567  
2568  /* DONT TOUCH THESE !!! */
2569  
2570 +
2571 +
2572 +
2573 +
2574 +
2575 +
2576  /*
2577   * LVM_PE_T_MAX corresponds to:
2578   *
2579 @@ -253,7 +249,7 @@
2580   *
2581   * Maximum PE size of 16GB gives a maximum logical volume size of 1024 TB.
2582   *
2583 - * AFAIK, the actual kernels limit this to 2 TB.
2584 + * AFAIK, the actual kernels limit this to 1 TB.
2585   *
2586   * Should be a sufficient spectrum ;*)
2587   */
2588 @@ -273,7 +269,7 @@
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) */
This page took 5.460055 seconds and 3 git commands to generate.