Hot and cold connection of devices. Hot plug

Original: Some Nifty udev Rules and Examples
Authors: Vimal Daga, Davender Singh
Publication date: June 28, 2012
Translation: A.Panin
Translation publication date: October 23, 2012

Thanks to the udev system developed by Greg Kroah-Hartman, Kay Sievers and Dan Stekloff, the process of connecting flash drives, hard drives, cameras and mobile phones to a system running Linux has become simple and manageable like never before. First implemented in the Linux kernel version 2.6, the udev system handles both hot-plugging devices to a running system and cold-plugging devices (attached before the system was powered on). In this article, we'll walk through the process of dynamically creating device files in the /dev directory and provide some examples of customizations for use or just for fun.

udev is a user-space implementation of the devfs device file system. The system includes the udevd service, configuration files, and rules files used to dynamically manage Linux device files located in the /dev directory in response to kernel-generated events (uevents). Udev has successfully completely replaced the old devfs implementation since Linux kernel version 2.6.

What was the need for a completely redesigned implementation of the device file management system? And why was the udev implementation so successful? To get an answer, you need to look at the history of the development of Linux OS device driver interfaces.

Each device file has two 8-bit values ​​associated with it: a minor identifier (minor number) and a major identifier (major number). Each device driver has a major ID; and all device files running under this driver have the same major identifier. Minor device IDs are different for different devices running this driver.

In early versions of Linux, the /dev filesystem contained one static file for each device that could be attached to the system (and controlled by a device driver). Unfortunately, this approach had a number of problems: there were not enough identifier values ​​to assign to all possible devices, especially in the face of a growing number of supported devices. Also, having more than 18,000 device files required a lot of additional disk space. These issues have been addressed by allowing udev to ignore the minor and major device file ID values.

When hot-plugging devices such as USB hardware, there was no consistency in naming and iding the device file. For example, on a system with two USB printers, one of the printers might be represented by /dev/usb/lp0 and the other by /dev/usb/lp1 - but there is no clear understanding of which printer is represented by which file. . This behavior may have changed depending on which device was turned on when the computer boots or connected before - or may change depending on whether the device is connected to a USB hub or directly to the system's USB port. This behavior has always been frustrating and confusing for users. The udev system allows you to set a permanent device name using rules.

Other udev features solve many of the problems inherited from devfs:

  • udev runs in user space, reducing the amount and complexity of kernel code.
  • udev allows you to assign a permanent device name that does not depend on the order in which devices are included and the location of the device on the bus.
  • udev dynamically modifies files in the /dev directory, creating files only for devices that are present and connected to the system. It is also possible to assign arbitrary device names using symbolic links to device files.
  • udev provides device information to user-space applications, removing the need to access kernel internals to obtain this information.

How udev works

The udevd service listens on a netlink socket for events generated by the kernel when a device is connected or disconnected. You can monitor these events with the udevmonitor command - run it, plug in a USB device such as a flash drive, and unplug it (newer distributions may not have udevmonitor - use udevadm in this case.)

During startup, udev mounts the tmpfs filesystem to the /dev directory. After that, device files are copied from the /lib/udev/device directory to the /dev directory, and udev starts accepting kernel events for cold-plugged devices. The /etc/udev/rules.d directory is used to change device settings, create symbolic links to device files, and more. For hot plug devices, udevd listens for kernel events using D-Bus, then gets the new device's attributes from the /sys filesystem and applies the rules based on the attributes - then a device file is created on the /dev filesystem. Udev also allows you to load dedicated device drivers using the "modalias" mechanism.

udev rules and examples

Udev provides the ability to change its behavior based on rules and configuration files. You can override how the rules that come with the system (usually found in /lib/udev/rules.d ) work, or add custom and specific features to suit your needs. Rules can be added to the /etc/udev/rules.d/ directory - the directory for individual custom rules.

Create your rules (that assign a device filename, create symlinks, set permissions, and do whatever you want) in this directory. To make sure that a rule comes before the others, make sure the file name starts with a number less than the rest of the rules that should run after it - for example, 10-local.rules .

Disable the root user account until the administrator connects his USB drive

BUS=="usb", SUBSYSTEM=="block", PROGRAM="/bin/enable_root_login"

In order for this rule to work, you need to develop an application or shell script with the given name in order to get the serial number of the device connected to the system and compare it with the known serial number of the administrator's device. If the serial numbers match, the program will remove the auth requisite pam_deny.so line from the /etc/pam.d/login file, which will allow login under account root user. If other USB devices are connected, no file changes will be made. On the contrary, as soon as the USB drive is disconnected, this line will be added to the file again.

This rule was tested on the RHEL 5.0 distribution and worked fine, however, when using the su command or when logging into single user mode on boot, this rule will not work. To disable root login when using the su command, you can do the following:

  1. Edit the /etc/security/access.conf file by adding the line root: ALL .
  2. Edit the file /etc/pam.d/system-auth , adding as the second line account required pam_access.so.
  3. Edit the file /etc/pam.d/su and make the first line of this file the line account include system_auth .

These actions, of course, must be performed by the enable_root_login program. After checking the serial number of the USB device for belonging to the administrator, the program should remove all changes made to the files, and if the attached device does not belong to the administrator, perform all the above actions on the files.

These steps will not prevent you from logging in as root in single user mode, however you can set a password on the GRUB bootloader to prevent easy access to single user mode.

You can use the following command to get information about the device serial number, device name, vendor ID, manufacturer name, and other parameters: udevinfo -a -p /sys/block/sdb

Newer distributions may not have udevinfo, in which case you should use udevadm instead of udevinfo .

Disable all USB ports

BUS=="usb", OPTIONS+="ignore_device"

The result of this rule will be to disable all devices connected to the USB ports of your system - USB printers, keyboards and mice will not work. Be careful when using!

Disable all block devices attached to USB ports

BUS=="usb", SUBSYSTEM=="block", OPTIONS+="ignore_device"

This rule disables recognition of block devices connected to USB ports. This rule can be useful for improving data security and privacy in an organization.

Assign a permanent name to the device file of the second IDE drive

Substitute sdb if you want to apply the rule to a different drive.

Ignore second USB SCSI/IDE drive connected via USB

KERNEL=="sdb", NAME="my_spare"

BUS=="usb", KERNEL=="hdb", OPTIONS+="ignore_device"

Add a symbolic link to a given file USB devices-mice

SUBSYSTEM=="input", BUS=="usb", SYSFS(serial)=="0000:00:1d.0", SYMLINK+=="MY-USB-MOUSE"

Change device filename based on device manufacturer

BUS=="usb", SYSFS(manufacturer)=="JetFlash", NAME="UNIVERSE"

This rule changes the device filename to "UNIVERSE" if the manufacturer of the USB flash drive is JetFlash.

Selectively allow the use of USB block devices using a special program

BUS=="usb", SUBSYSTEM=="block", PROGRAM="/bin/usbc.jar", RESULT!="my", OPTIONS+="ignore_device"

If the program outputs "my", the device can be used, otherwise the device is ignored.

Imagine an ordinary morning in one of the high-rise buildings of the sleeping area of ​​our beloved city: a toilet bowl, a shower, a shave, tea, brush your teeth, water for the cat (or in any other order) - and go to work ... Everything is automatic and without hesitation. As long as cold water flows from the cold water tap, and hot water flows from the hot water. And sometimes you open a cold one, and from there - boiling water!! 11#^*¿>.

Let's figure it out.

Cold water supply or cold water

The local pumping station supplies water to the main from the water utility network. A large supply pipe enters the house and ends with a valve, after which there is a water meter.

In short, the water meter assembly consists of two valves, a strainer and a meter.



Some have an additional check valve.

and water meter bypass.

The water meter bypass is an additional meter with valves that can feed the system if the main water meter is serviced. After the meters, water is supplied to the house main


where it is distributed along risers that lead water to apartments on floors.



What is the pressure in the system?

9 floors

Houses up to 9 floors high have bottom pouring from bottom to top. Those. from the water meter through a large pipe, water leaves through the risers to the 9th floor. If the vodokanal is in a good mood, then at the input of the lower zone there should be approximately 4 kg/cm2. Given a pressure drop of one kilogram, for every 10 meters of water column, residents on the 9th floor will receive approximately 1 kg of pressure, which is considered normal. In practice, in old houses, the input pressure is only 3.6 kg. And the inhabitants of the 9th floor are content with even less pressure than 1kg / cm2

12-20 floors

If the house is higher than 9 floors, for example 16 floors, then such a system is divided into 2 zones. Upper and lower. Where the same conditions remain for the lower zone, and for the upper zone the pressure is raised to about 6 kg. In order to raise the water to the very top into the supply line, and with it the water rises up to the 10th floor. In houses above 20 floors, the water supply can be divided into 3 zones. With such a supply scheme, the water in the system does not circulate, it stands on a backwater. In a high-rise apartment, on average, we get pressure from 1 to 4 kg. There are other values, but we will not consider them now.

Hot water supply or DHW

In some low-rise buildings, hot water is connected in the same way, it stands on a backwater without circulation, which explains the fact that when a hot water tap is opened, cold, cooled water flows for some time. If we take the same house with 16 floors, then in such a house the hot water system is arranged differently. Hot water, like cold water, is also supplied to the house through a large pipe, and after the meter it goes to the house main

which raises the water to the attic where it is distributed along the risers and descends to the very bottom into the return line. By the way, hot water meters count not only the volume of lost (consumed) water in the house. These counters also count the temperature loss (hygocalories)

The temperature is lost when water passes through apartment heated towel rails, which play the role of risers.

With this scheme, hot water always circulates. As soon as you turn on the faucet, hot water is already there. The pressure in such a system is approximately 6-7 kg. on the supply and slightly lower on the return to ensure circulation.

Due to circulation, we get pressure in the riser, in the apartment 5-6 kg. and immediately we see the difference in pressure between cold and hot water, from 2 kg. This is precisely the essence of squeezing hot water into cold water in the event of a malfunction of plumbing fixtures. If you have noticed that you still have more pressure on hot water than on cold water, then be sure to install a check valve at the cold inlet, and control valves can be included in the hot water inlet, which will help equalize the pressure by about one digit with cold. Pressure regulator installation example

hot plug- hot plug) - terms meaning shutdown or connection electronic equipment to / from the (computer) system during its operation without turning off the power and stopping (the system) (HotPlug), as well as replacing (reconnecting) the unit as a whole ( hot swap ). There is also a term for the opposite of hot swap - Cold swap , that is, all (re)connections are made after the system is stopped and the voltage (residual potential) is removed.

The equipment is divided according to this principle into allowing hot swap and not allowing.

Story

Previously, equipment designed to be plugged in during replacement work was only used in expensive systems and was considered difficult to design. Last time similar systems have become common even on inexpensive computers.

  • Designed to be hot-swappable and therefore hot-swappable to PCMCIA, USB, FireWire, Fiber Channel, and eSATA standards.
    Among the devices of this type are flash drives, some hard drives, including for arrays in servers, PCI-X, PCI Express, ExpressCard (PCMCIA, also formerly called PC Cards) expansion cards that are used in laptops, and even some power supplies. .
  • Does not fully hot-swap SATA disk interfaces and does not fully support the IDE protocol (IDE is hot-pluggable).

System design

Computers designed to replace equipment on the fly must somehow detect when a device is disconnected, and also contain electrical circuits that are insensitive to power surges when connecting and disconnecting. In addition, the software part must be designed for a sudden loss of communication with the device.

Some hot-swap schemes require a detach command to be issued first, which simplifies their design, but threatens data integrity if the device is not detached in the correct way or an error occurs in the device.

More complex schemes have a margin of redundancy and easily restore data in the event of a sudden shutdown of the device.

The term "hot swap" is used in two senses. On the one hand, it means the ability to disconnect or connect the device without turning off the power. On the other hand, it can also imply automatic device detection when connected. The first meaning of the term applies to interfaces RS-232, FireWire and the simplest implementations of SCSI, the second meaning - to USB, FireWire, PCI Express and sophisticated SCSI variants.

Nest design

The extreme contact pads of the power supply are made longer than the internal signal

Most modern devices hot-swappable, moving contacts are used. One of them is made longer than the others in order to be the first to come into contact with the attached part, a ground wire is connected through it. The remaining contacts are made shorter, in total there can be up to 3 different lengths. The delay between the connection of the first contact and subsequent ones is from 25 to 250 milliseconds.

Power circuits are connected in two stages: in the first, a current-limited circuit is connected using longer contacts, and then with shorter contacts, full power supply. All circuits involved in the connection contain protection against static electricity.

Here is an example of a typical connection sequence:

  1. The longest contacts are closed (ground). This ensures the electrical safety of the connection and protection against static charge.
  2. The long or medium pre-feed contacts close. The input circuits of the power circuits are being charged.
  3. Short power contacts are connected.
  4. The connection is considered established. The power-up signal turns on.
  5. The soft power-on circuit energizes the device.
  6. Delay in tens of milliseconds.
  7. The power circuit has completed the soft connection. The power-up signal turns off.
  8. The device starts full operation.

Of particular difficulty is the connection of several devices, since the connection of a second, third device may disrupt the operation of an already connected one. To combat this phenomenon, filters are used in the output circuits or a temporary logical shutdown of data transmission.

Hot plugging in software

The term "hot plug" is also used in relation to software and means the ability to change the program without stopping its execution. Only a few programming languages ​​support this feature, including Lisp, Erlang, and Smalltalk. The Java language only supports this feature while running the debugger (Java Platform Debugger Architecture, JPDA).

The domain-oriented programming language 1C v8 provides the ability to change the code while the program is running. (http://v8.1c.ru/overview/release_8_1_5/administration.htm section "Updating configuration parts"). Since individual modules are compiled at the time of program execution, and when a module is changed, it is compiled again in the session, this is not really a "hot plug". You need to re-create the session for the changes to take effect, and only for this user (others need to restart the new session). In version v7, this feature was also present when using additional software tools (http://openconf.1cpp.ru/vk/turbomd/) and the standard command #LoadFromFile.... (you only need to reopen the form or report). In general, when using interpreted programming languages ​​(with saving program texts inside modules), "hot plugging" is implemented simply by replacing texts.

Rotted old plumbing in the apartment. Perspiration on the pipes, fistula after fistula; turn off the water, and then turn it on again - rust is gushing from the taps. And it is planned to repair the kitchen with a bathroom, and the old pipes are not something to touch or breathe - it's scary to look at them. We need to change, but the work is expensive. Is it possible to replace the apartment plumbing with your own hands? Yes, you can, and without any permits-designs. It will only be necessary to agree with the DEZ locksmith to shut off the water supply to the risers for a maximum of an hour; most likely, it will be possible to manage in 10 minutes. Or warn the neighbors, if not harmful, and block / re-apply yourself.

Replacement procedure

The replacement of the water supply is carried out in a certain sequence. Work "by eye" and "on the go" in non-professional performance often ends in a leak. The work plan is something like this:

  1. Choice of material for new pipes.
  2. Choice of hot and cold water distribution scheme.
  3. Development of a water supply scheme for an apartment.
  4. Calculation of the diameter of pipes according to the selected material and scheme.
  5. Preparation of the mounting tool.
  6. Purchase of materials.
  7. Assembly of selection and accounting units, their installation on risers and registration.
  8. Dismantling of old pipes and plumbing fixtures.
  9. Connection of HMS and aquastop, if provided.
  10. Connecting a flask filter (with HMS is required).
  11. Installation of hot and cold water pipes.
  12. Installation and connection of plumbing, old or new.
  13. Test water supply; elimination of identified defects.
  14. Installation and connection of the boiler.

HMS, flask filter and aquastop

HMS, or hydromagnetic system, has long been used in industry to prepare water for filtration. In everyday life, this device, without going into details, converts impurities in water into a fine suspension, which then settles in the filter in the form of sludge and is periodically removed. HMS is absolutely harmless, does not require power supply and maintenance during operation, but it necessarily requires the installation of a water meter in an antimagnetic design (these are more expensive) and, after the water flow, a combined flask filter.

The flask filter consists of three sections connected in series: the first one collects sludge, the second one removes chlorine, and the third one is used for fine purification of water and its softening. The latter (no one has been drinking tap water for a long time) is especially important for the washing machine boiler.

HMS with flasks cost a lot, but they protect well not only equipment, but also health. Complain or not, be indignant - do not be indignant, and drinking water is firmly held in the ten most scarce resources in the world, and there are no global programs that can bring its quality to the level of at least the middle of the last century, and are not foreseen. In general, the salvation of drowning people is the work of the drowning people themselves.

Aquastop is also a useful device, it also does not require power supply and maintenance, but its function is different. With a sharp increase in current (breakthrough) of water, the aquastop is triggered and its valve cuts off the entire apartment from the riser. Aquastops come in different systems, including electrodynamic ones, so an anti-magnetic counter is also needed when installing an aquastop.

Pipe selection

A new plumbing in an apartment begins with the choice of pipes. Steel in everyday life has become obsolete, and you have to choose from metal-plastic, plastic and brazed copper. This stage of work is perhaps the most responsible - the wrong choice will nullify all the efforts, expenses and troubles.

Copper

One can say about copper water pipes right away: their propagandists do not know what they are talking about. Or they know, but they don’t set themselves. Firstly, copper oxide forms on copper in contact with water - the same verdigris that Tom Sawyer talked about to Huckleberry Finn. Yes, a person needs copper, but in negligible amounts in the form of a microelement, and not as part of a strong poison. As a counterargument, they say that copper forms a protective film with chlorine from water. Absurd for anyone who remembers at least school chemistry.

Secondly, the composition of the solder for copper includes tin. White tin, a soft metal, over time turns into its other, as chemists say, allotropic modification - gray tin, a crumbly powder. That is, by installing copper pipes (very expensive), we thereby 100% guarantee leakage. And the payment for the work of a company specializing in copper pipes, since it is impossible to solder them correctly on your own.

metal-plastic

Metal-plastic pipes are quite expensive, but they can be connected by hand without experience. Metal-plastic plumbing is assembled on special threaded assemblies with gaskets or under crimping - fittings. In addition, metal-plastic pipes can be smoothly bent. Hydrodynamic resistance and pressure loss in metal-plastic are very small.

To insert a pipe into a fitting, you need a pipe cutter, press tongs and a set of reamers (reamers) for the diameter of the pipes. With their help, work goes effortlessly, and with improvised means - a full guarantee of leakage. In addition, the life of gaskets in fittings is limited, and over time, the joint begins to drip. Therefore, bricking metal-plastic into walls is unacceptable, and it is strongly recommended not to hide it in strobes.

It is recommended to conduct water supply with metal-plastic in separate open areas, where the minimum resistance to water flow and the possibility of a simple and quick bulkhead of the joint are important: when connecting a boiler, washing machine, sink, etc. Adapters from metal-plastic to other types of pipes are always on sale.

Plastic

Plastic apartment plumbing has now become the standard, but plastics are different. To make the right choice, you need to know their properties and features.

Polybutylene (PB)

Flexible plastic with good thermal conductivity for plastic. Holds temperatures up to 90 degrees. A properly soldered joint is absolutely reliable. Pretty expensive. Used for underfloor heating.

Polyethylene (PE)

Cheap, but for hot water, polyethylene reinforced pipes are needed; ordinary polyethylene does not hold 60 degrees. It is impossible to bend and glue, the soldered joint reliably holds a pressure of no more than 3.5 atm, and the water pressure in the city water supply can be up to 6 atm (0.6 Mbar) for cold water and 4.5 atm for hot water, so that there is a possibility of a sudden breakthrough. Hydraulic resistance, however, is the smallest of all.

It seems that polyethylene pipes are bad for everyone, but they have an advantage that can be worth all their shortcomings: they are not afraid of freezing. The ice cork bursts them, and when it melts, they shrink again, and do not burst, even if you crack. Therefore, the installation of a polyethylene water supply system is strongly recommended in unheated, seasonal and underground premises. There is no alternative to polyethylene. But with a constantly filled system, an aquastop is needed.

PVC (PVC)

The properties of polyvinyl chloride (PVC) are well known: chemically resistant, inexpensive, heat resistant up to 80 degrees, easy to glue, but not very strong and afraid of ultraviolet radiation. Joints, both soldered and glued, come out more brittle than solid material, so the danger of a breakthrough remains and an aquastop is needed. Replacing individual sections of glued PVC, of ​​course, is more difficult than for collapsible metal-plastic, but easier than for soldered joints: heating the joint with a household hair dryer, the joint can be separated, and then glued again. In general, the option is budgetary or for a novice master with a length of the main branch from the riser to the farthest draw point of no more than 10 m and with no more than 7 sampling points.

Propylene (PP)

Laying an apartment water supply with polyisopropylene pipes (propylene) is now generally accepted. The material is not very expensive, durable, resistant, soldered joints retain all the qualities of the base, heat resistance - up to 130 degrees, properly soldered holds up to 12 atm. The hydraulic resistance is higher than that of PVC, but anyway, the accumulation of plaque in the lumen is minimal, and with HMS it is excluded. There are only two disadvantages when doing it yourself:

  • It does not stick, and soldering requires special equipment and strict adherence to technology.
  • It has a fairly high coefficient of thermal expansion. Immured in a wall or hidden in a strobe, it can bend and break the tile, therefore, when laying each pipe, you need to put on a stocking made of merylon or synthetic winterizer, which increases the cost of work.

However, the propylene pipeline is by far the only one that can be done once and for all and forgotten. Therefore, we will dwell on the soldering of propylene separately, especially since the soldering of other plastics differs only in a lower temperature (110-130 degrees for polyethylene and about 150 for PVC).

Propylene soldering

Soldering propylene with a handicraft “iron” soldering iron end-to-end (see the figure on the right) is unacceptable:

  1. Pollution accumulates on the “sausage” inside, and the pipeline assembled in this way is more prone to clogging than steel.
  2. The pressure of the water, bursting the pipes, tends to break the joint. At 16 degrees in the pipe and 20-25 outside, after about three months the fatigue threshold of the material is surpassed, and the joint flows.

The assembly of the propylene pipeline is carried out on fittings for soldering - straight (for connecting pipe sections), angular, tees, crosses. The pipe heated to softening is inserted into the holder of the also heated fitting, and the joint freezes. In this case, water pressure, on the contrary, presses the pipe against the casing from the inside, providing strength, and only sealing remains for the fused zone. The rather high rigidity of propylene does not allow the clip covering the pipe to expand elastically. It is this design of the connection, combined with the properties of the material, that makes the propylene pipeline suitable for immuring into walls for decades.

Note: a more or less decent soldering iron for propylene costs at least 2000 rubles. and is still unsuitable for something, but does not wear out from work. Therefore, you do not need to buy it, it is better to rent it.

  • For hidden wiring in a typical apartment in strobes or monolithic - definitely propylene.
  • For branches of great length with a large number of points of water intake - open metal-plastic or in channels with removable covers.
  • For country houses, seasonal rental housing, country houses with remote outbuildings, greenhouses, etc. - polyethylene.
  • For budget repairs or in areas with a shortage of water, low pressure in the water supply, with poor quality water - PVC.

Wiring diagram

Collectors-combs

There are two schemes for drawing water in the premises: serial and parallel. With a serial scheme, the points of analysis are connected to a common pipe through tees. This scheme is the most economical, but with a long wiring length, a large number of parsing points and / or with low water pressure, it is not suitable, as it greatly reduces pressure.

In this case, the water intake is done in parallel from the “comb” collector, see fig. A comb is an assembly of bypass valves, from each of which there is a solid branch to its point of analysis. The valves regulate the pressure separately by points. The branches to the points are made of metal-plastic or polyethylene: in this case, their low hydraulic resistance plays a role, and when laid in a single piece, they are quite reliable.

Development of a water intake scheme

The water supply scheme in the apartment is needed primarily for oneself, so as not to get confused, not to miscalculate, and then to know exactly where everything is - no special permission is required for this work. But when registering the meter, the water utility inspector may ask you to look at the diagram, so you need to draw it correctly.

A complete scheme according to all the rules is a serious job for a knowledgeable specialist; for example - in the large figure, the water supply scheme of a private house with a summer kitchen, which is necessary for the project to be approved. But to replace the pipes in the apartment, you don’t need to bother like that, it’s enough that the diagram clearly shows and understands:

  1. Hot and cold water pipes, their type and lumen diameter.
  2. Metering devices.
  3. Emergency valves and drains.
  4. Stop valve.
  5. Points of analysis with indication of consumers.
  6. Backup branches and devices.
  7. Direction of water flow.

To make all this clear not only to yourself, or to yourself a year later, certain rules must be observed when drawing. Let's look at examples, see fig. On the left - more or less okay, but with comments, on the right - wrong:

  • The scheme on the right is made in isometry - for beauty, or what? The intersections of the pipes confuse her, and she does not give an idea of ​​\u200b\u200bthe real location of the analysis points: the washing machine with the boiler comes out under the floor.
  • There are also too many current arrows where it is already clear where it flows, which also confuses the circuit.
  • In the same place, shut-off valves with metering devices are depicted indistinctly and not according to the rules.
  • In the same place - the type and diameter of the pipes are not indicated.
  • In the same place - who, where and when saw that water was supplied to the boiler from above, and the toilet was flushed through the ebb?
  • But in the diagram on the left, it’s not even clear to a specialist that the boiler (6) is a backup. The remark will be: “Where is the check valve for hot? Without it, when the supply is stopped, the boiler will drive its own into the hot riser if the valve (10) is not closed. But this is already in essence and with full understanding.

Correct simplified plumbing scheme in the apartment

An example is arbitrarily, not according to the rules for designing design documentation, but completely understandable and without frills, the completed water intake scheme is shown in the following figure. This is also an example of a parallel drawdown; where the combs, of course.

Pipe calculation

Before finally choosing pipes, you need to calculate at least approximately their diameter. This is not necessary for "smartness" - the narrower the pipe, the cheaper it is, on the one hand. On the other hand, a too small diameter pipe for a water supply will cause turbulence in the flow in it. At the same time, the throughput of the pipe drops sharply, and at normal pressure at the inlet from the tap it will barely ooze.

The exact calculation of the pipeline is a matter of highly qualified specialists, but for a city apartment, in order to flow normally, you can figure it out yourself. The initial data is:

  1. The minimum allowable pressure is 0.3 at.
  2. Pressure loss per 1 m of a 16 mm propylene pipe - 0.05 at.
  3. The average pressure loss for apartment wiring per unit of fittings and fittings is 0.15 at.
  4. Pressure loss in the selection and accounting unit - 0.25 at.
  5. With normal values ​​​​of pressure at the inlet to the riser of 1.5-4.5 atm, periodic turbulence is inevitable in a 12 mm pipe, and is not observed in 16 mm pipes.
  6. The headroom for the farthest point is at least two times.

It remains to find out the pressure (pressure) at the inlet, and you can determine whether, with the serial wiring of such a running pipe, there will be enough pressure for the farthest faucet or you will have to take it wider and more expensive. The pressure at the bottom of the riser can be obtained from the pressure gauge in the basement or from the building operator; then subtract 0.6 atm per floor. You can also estimate for neighbors based on the same 0.6 at / floor: if, say, three floors up from the taps, it still flows, then we have a good 2 at. But in high-rise buildings, such a trick does not work: in order not to overly increase the cost of apartment wiring, they make separate risers for the lower and upper, and even for the lower, middle and upper floors.

Calculation example: the second floor of a nine-story building; the residents of the upper floors do not complain about the water. We have at least 4 at pressure. 11 units of fittings (5 tees, 6 elbows, 1 valve) give 1.65 atm losses. The length of the pipe from the riser to the far wall of the kitchen is 6.5 m, which is another 0.325 atm of loss. In total, with the selection and accounting unit, we have 0.325 + 1.65 + 0.25 = 2.225 atm of losses. Too much, you need to check the pressure with a pressure gauge and, most likely, take the main pipe 20-25 mm, or get divorced in parallel from the comb, otherwise you can stay “dry” in the dry summer.

Note: from this it is clear how important it is to straighten the pipes and how undesirable they are to lengthen and clutter up with fittings.

The dependence of losses in pipes and fittings is non-linear: they depend on the flow velocity, which, in turn, depends on the cross section of the pipe lumen. A slight increase in the diameter of the pipe drastically reduces losses, so the usual 20 mm pipe wiring for apartments with taps to 16 mm points works well in most cases. In difficult cases, an accurate calculation can be made according to SNiP, internal water supply and sewerage of buildings. There are all the necessary formulas and nomograms; the calculation can be done by a person with an engineering education of any profile.

You just need to keep in mind that on this account there are already three SNiPs with the same index: 2.04.01-85, 2.04.01-85 (2000) and 2.04.01-85 * “(Domestic water supply and drainage systems in buildings) ". Correct - SNiP last.

Tools, materials, dismantling of the old

Special tools for assembling apartment pipelines are described above in the course of the presentation. For the purchase of materials, of course, you will need to calculate the footage, nomenclature and quantity in place. Dismantling of old pipes is done in the usual ways. It is better to do it after installing and registering the water meter, so as not to turn off the water to the floors for a long time.

We will give only one piece of advice: do not take valves with a lever. It is made of silumin or plastic and tends to break off at the most inopportune moment, just when you need to urgently close it. Take ball valves with a butterfly handle. Round corrugated handles also do not break, but wet or sweaty hands slide on them.

Accounting and control

The selection and accounting unit consists of a shut-off valve, a coarse filter, a water meter and a check valve. Assembled as shown in the picture. Each of the devices indicates the direction of the water flow for it, it must be observed during assembly.

The assembly is assembled with waterproofing of the connections with the FUM tape and is also connected to the riser, having previously blocked the water; Remember to close the shut-off valve before supplying water. This is the only operation, and a short-term one, requiring turning off the water supply to neighbors in the riser.

Separate meter units are needed for cold and hot water. It is highly desirable that the counters and valve handles be highlighted in color. The meter readings should be clearly readable without any additional operations (hatch removal, etc.), so it is often necessary to pre-assemble a part of an integral pipeline, sometimes of a rather bizarre configuration, to connect metering devices to the riser. In addition to pipes and a soldering iron, for this you will need transitional couplings from plastic to metal MPV - a threaded inner coupling. Plastic is connected to metering units using MRN - external threaded couplings.

The meters are sold sealed, but this does not mean that you can immediately call the water utility and pay for water according to consumption. The factory seal is for this (the Russian land is rich in craftsmen) so that no one gets into the meter and twists or files anything there. The factory seal must be protected; without it, the meter is considered unusable, as well as without a certificate for it.

When installing water meters, you need to declare to the water utility and call its inspector. You can use water before he arrives, the inspector does not need zero readings, he will write down the initial ones, seal the meter and filter drain with his seal. Payment for water consumption will go after registration of metering devices.

HMS, aquastop, filter

Although the design of the HMS is non-separable and does not allow stealing water with its help, and this device cannot be sealed, connecting the HMS to the meter is unacceptable: the meter impeller can become clogged with sludge. HMS with a flask filter is connected after metering devices; filter - immediately after HMS. An aquastop can be connected immediately after the filter, but if it is electrodynamic, the magnetic field of the HMS can cause its false operation, but it makes no sense to attribute the aquastop far from the riser: it does not react to a breakthrough before it.

Video: an overview of the layout options for plumbing elements

Pipeline installation

So, now we do the plumbing. The assembly of pipes has already been described, but the installation of the entire system also has non-construction features, such as the arrangement of channels in the screed. The latter should pass no further than 150 mm from the wall and no closer than 200 mm to the furniture. Plumbing fixtures, of course, are removed before starting pipe laying.

First of all, you need to install arcs - plastic strips with MRV squares for mixers. They are attached to the main wall with self-tapping screws in dowels. When attaching, you need to take into account the thickness of the finish: plaster and tile or other decorative coating.

Without a lot of building experience, it is very difficult to achieve the location of the outlet nozzles flush with the wall. It is better to make them PROPERTIES above the finished wall half the width of the side of the decorative mixer caps in advance: if the caps are unregulated, they can be easily adjusted on an emery wheel or manually on an emery bar.

The next moment is the assembly of pipeline sections. The most convenient way is to assemble it on the table and put it entirely in strobes. But then the question arises: how to run pipes through walls? There are no problems with metal-plastic, it is all on detachable fittings, and for brazed pipes, two methods can be offered:

  • With the help of MPH / MRV adapters and metal-plastic inserts. In an apartment, this is quite reliable, and in the corners above the strobes, you can make removable hatches for revision and repair of threaded connections.
  • Install pipelines locally. This requires a compact soldering iron. This one is more expensive, and you need to work in cotton gloves so as not to accidentally burn yourself.

The fourth point is soldering. One solder takes 15 mm of pipe. That is, if there is exactly 1 m between two fittings, you need to cut 1030 mm; if 0.6 m - 630 mm etc.

The fifth point is the bending of metal-plastic pipes. The minimum allowable bending radius is 5 outer diameters of the pipe. You can come across recommendations: they say, put a spring in there, fill it with sand, and you can generally bend it at an angle, and pull out the spring and pick out the sand with a wire hook. In no case: the coating of the pipe deteriorates, the residual stresses in it are much higher than the permissible ones, and the metal-plastic pipe acquires the properties of a very poor rusted steel.

And finally, . This is a separate production cycle, and it is done after the commissioning of the water supply system. The pipes for the boiler are made in advance, but the valves on them (they are definitely needed on both) are blocked immediately after the pipes are installed, and the pipes are additionally muffled.

Video: an example of a mounted plumbing

There are two different ways to consider hot plugging. The kernel views hotplugging as an interaction between the hardware, the kernel, and the kernel driver. Users think of hotplugging as an interaction between the kernel and userspace through a program called /sbin/hotplug . This program is called by the kernel when it wants to notify userspace that some type of hotplug event has just occurred in the kernel.

Dynamic Devices

The most common use of the meaning of the term "hot plug" occurs when discussing the fact that most all computer systems can now handle devices that appear or disappear when the system is turned on. This is very different from computer systems just a few years ago, when programmers knew they only needed to scan all devices at boot time and never had to worry about their devices disappearing when the power to the entire machine was turned off. Now, with the advent of USB, CardBus PCMCIA, IEEE1394, and PCI hot-pluggable controllers, the Linux kernel needs to be able to work reliably no matter what hardware is added or removed from the system. This places an additional burden on the writer of the device driver, as they must now always work with a device that suddenly breaks out of control without prior notice.

Each bus type handles device loss differently. For example, when a PCI, CardBus, or PCMCIA device is removed from the system, it usually happens before the driver has been notified of the action through its remove function. Before this happens, all reads from the PCI bus return all bits set. This means that drivers need to always check the value of the data they have read from the PCI bus and be able to properly process the 0xff value.

An example of this can be seen in drivers/usb/host/ehci-hcd.c , which is a PCI driver for a USB 2.0 (High-Speed) controller board. It has the following code in its main handshake loop to detect that the controller board has been removed from the system:

result = readl(ptr);

if (result == ~(u32)0) /* map removed */

Return -ENODEV;

For USB drivers, when the device the USB driver is associated with is removed from the system, any pending urbs that were sent to the device first fail with a -ENODEV error. The driver should recognize this error and appropriately clean up any pending I/O, if any.

Hot plug devices are not limited to traditional devices such as mice, keyboards, and network cards. There are many systems that now support the removal and addition of entire processors and memory cards. Fortunately, the Linux kernel properly handles the addition and removal of such basic "system" devices, so individual device drivers don't have to worry about these things.

/sbin/hotplug utility

As mentioned earlier in this chapter, when a device is added to or removed from the system, a "hot plug event" is generated. This means that the kernel calls the userspace program /sbin/hotplug . This program is usually a very small bash script that simply hands off execution to a list of other programs that are in the /etc/hotplug.d/ directory tree. For most Linux distributions, this script looks like this:

DIR="/etc/hotplug.d"

for I in "$(DIR)/$1/"*.hotplug "$(DIR)/"default/*.hotplug ; do

If [ -f $I ]; then

Test -x $I && $I $1 ;

done

exit 1

In other words, the script looks for all programs with the .hotplug suffix that might be interested in this event and calls them, passing them a number of different environment variables that have been set by the kernel. More information on how the /sbin/hotplug script works can be found in the program comments and in the hotplug(8) manual page.

As mentioned earlier, /sbin/hotplug is called when a kobject is created or destroyed. The hotplug program is called with one argument command line A that represents the title for this event. The main kernel and a specific subsystem are also involved in setting a set of environment variables (see below) with information about what just happened. These variables are used in hotplug programs to determine what has just happened in the kernel and whether there is some special action that needs to take place.

The command line argument passed to /sbin/hotplug is the name associated with this hotplug event, as determined by the kset assigned to the kobject. This name can be set by calls to the name function, which is part of the kset's hotplug_ops structure described earlier in this chapter; if this function is missing or has never been called, the name of the kset itself is used.

The default environment variables that are always set for the /sbin/hotplug program are:

ACTION

The string add (add) or remove (delete), depending on whether the given object was just created or destroyed.

DEVPATH

Path to a directory in the sysfs filesystem that points to the kobject that is currently either created or destroyed. Note that the sysfs filesystem mount point is not added to this path, so its definition is left to the userspace program.

SEQNUM

The sequence number for this hotplug event. The sequence number is a 64-bit number that increments with each hotplug event generated. This allows user space to sort hotplug events in the order that the kernel generates them, since it is possible for user space programs to work out of order.

SUBSYSTEM

The same string passed as a command line argument as described above.

A number of different bus subsystems for calling /sbin/hotplug add their own environment variables when a device associated with the bus has been added to or removed from the system. They do this in their hotplug callback specified in the struct kset_hotplug_ops assigned to that bus (as described in the Hotplug Operations section). This allows user space to be able to automatically load the necessary modules that may be needed to control a device that has been detected on the bus. Here is a list of the different bus types and the environment variables they add to the /sbin/hotplug call.

IEEE1394 (FireWire)

All devices on the IEEE1394 bus, also known as FireWire, have a name option for /sbin/hotplug and the SUBSYSTEM environment variable is set to ieee1394 . The Ieee1394 subsystem also always adds the following four environment variables:

VENDOR_ID

24-bit Vendor ID for the IEEE1394 device.

MODEL_ID

24-bit model ID for an IEEE1394 device.

GUID

The 64-bit GUID for this device.

SPECIFIER_ID

24-bit value that specifies the owner of the protocol specification for this device

VERSION

A value that specifies the protocol specification version for this device.

Net

All network devices generate a hotplug message when the device is registered or unregistered with the kernel. The /sbin/hotplug call has a name parameter and the SUBSYSTEM environment variable is set to net and only adds the following environment variable:

INTERFACE

The name of the interface that was registered or unregistered from the kernel. Examples of it are lo and eth0 .

PCI

Any devices on the PCI bus have a name parameter and the SUBSYSTEM environment variable is set to pci . The PCI subsystem also always adds the following four environment variables:

PCI_CLASS

The PCI class number for this device, in hexadecimal.

PCI_ID

The vendor and PCI device IDs for this device, in hexadecimal, concatenated in the format vendor:device .

PCI_SUBSYS_ID

Vendor and PCI subsystem IDs combined in the format subsys_vendor:subsys_device .

PCI_SLOT_NAME

The "name" of the PCI slot given to the device by the kernel in the format domain:bus:slot:function . An example would be 0000:00:0d.0 .

Input

For all input devices (mouse, keyboards, joysticks, and so on), a hotplug message is generated when a device is added to and removed from the kernel. The /sbin/hotplug option and the SUBSYSTEM environment variable are set to input . The input subsystem also always adds the following environment variables:

PRODUCT

A multi-valued string listing the values ​​in hexadecimal, without leading zeros, in the format bustype:vendor:product:version.

The following environment variables may be present if the device supports them:

NAME

The name of the input device, as given by the device.

PHYS

The physical address of the device that the input subsystem gave to this device. It should be stable, depending on the location of the bus that the device was connected to.

They all come from an input device handle and are set to the appropriate values ​​if the given input device supports it.

USB

Any devices on the USB bus have a name parameter and the SUBSYSTEM environment variable is set to usb . The USB subsystem also always adds the following environment variables:

PRODUCT

A string in the format idVendor/idProduct/bcdDevice

TYPE

String in format bDeviceClass/bDeviceSubClass/bDeviceProtocol, which defines these USB device dependent fields.

If the bDeviceClass field is set to 0, the following environment variable is also set:

INTERFACE

String in format bInterfaceClass/bInterfaceSubClass/bInterfaceProtocol, which defines these USB device dependent fields.

If the CONFIG_USB_DEVICEFS kernel build option is selected, which selects that the usbfs filesystem be built in the kernel, the following environment variable is also set:

DEVICE

A string that shows where the device is located in the usbfs filesystem. This line has the format /proc/bus/usb/USB_BUS_NUMBER/ SB_DEVICE_NUMBER, where USB_BUS_NUMBER is the three-digit number of the USB bus the device is connected to, and USB_DEVICE_NUMBER is the three-digit number that was assigned by the kernel for this USB device.

SCSI

All SCSI devices generate a hotplug event when a SCSI device is created or removed from the kernel. The /sbin/hotplug call has a name parameter and the SUBSYSTEM environment variable set to scsi for each SCSI device that is added to or removed from the system. No additional environment variables are added by the SCSI system, but it is mentioned here because there is a special user-space SCSI script that can determine that SCSI drivers (disk drive, tape drive, normal, etc.) should be loaded for the specified device SCSI.

Notebook Docking Stations

If a Plug-and-Play-enabled laptop docking station is added to or removed from a running Linux systems(by plugging a laptop into the station, or removing it), a hotplug event is generated. The /sbin/hotplug call has a name parameter and the SUBSYSTEM environment variable set to dock . No other environment variables are set.

S/390 and zSeries

On the S/390 architecture, the channel bus architecture supports a wide variety of hardware, each of which fires /sbin/hotplug events when they are added to or removed from the Linux virtual system. All of these devices have a name parameter for /sbin/hotplug and the SUBSYSTEM environment variable set to dasd . No other environment variables are set.

Using /sbin/hotplug

Now that the Linux kernel calls /sbin/hotplug for every device added or removed from the kernel, a number of very useful tools have been created in user space to take advantage of this. Two of the most popular tools are Linux hotplug scripts and udev .

Linux hotplug scripts

Linux hotplug scripts started as the very first user calling /sbin/hotplug . These scripts look at the various environment variables that the kernel sets to describe the device it has just discovered and then try to find a kernel module that matches that device.

As discussed earlier, when a driver uses the MODULE_DEVICE_TABLE macro, the program, depmod , takes this information and creates the files found in /lib/module/KERNEL_VERSION/modules.*map. The * sign is a distinction, depending on the type of bus that the driver supports. Currently, module card files are created for drivers that work with devices that support the PCI, USB, IEEE1394, INPUT, ISAPNP, and CCW subsystems.

Hotplug scripts use these modulemap text files to define a module to attempt to load it to support a device that was recently discovered by the kernel. They load all modules and don't stop at the first match, so as to let the kernel decide which module is best suited. These scripts do not unload all modules when devices are removed. If they tried to do this, they could accidentally turn off devices that are also controlled by the device driver that was removed.

Note that now that the modprobe program can read MODULE_DEVICE_TABLE information directly from modules without the need for modulemap files, hotplug scripts can be reduced to a small wrapper around the modprobe program.

udev

One of the main reasons for creating a single driver model in the kernel was to allow user space to manage the /dev tree in a dynamic manner. This used to be done in userspace by the devfs implementation, but that codebase has slowly rotted away due to a lack of an active maintainer and some unrecoverable underlying bugs. Several kernel developers realized that if all device information were exported to user space, it could do all the necessary management of the /dev tree.

devfs has some very significant flaws in its design. It requires each device driver to be modified to support it, and it requires the device driver to specify the name and location in the /dev tree where it is placed. It also does not properly handle dynamic major and minor numbers, forcing the device naming policy to belong to the kernel and not to user space. The Linux kernel developers really hate having a policy in the kernel and since the devfs naming policy doesn't follow the Linux Standard Base specification, it really bothers them.

Ever since the Linux kernel started being installed on huge servers, many users have faced the problem of how to manage a very large number of devices. With disk drive arrays of over 10,000 unique devices, it is a very difficult task to ensure that each disk is always named with the same exact name, wherever it is placed in the disk array or when it is discovered by the kernel. This is the same problem that desktop users suffer when they try to connect two USB printers to their system and then realize that they have no way of ensuring that the printer known as /dev/lpt0 is not changed and reassigned to another printer. in the event of a system reboot.

Thus, udev was created. It relies on all device information exported to userspace via sysfs and notification via /sbin/hotplug that a device has been added or removed. Policy decisions, such as what name to give the device, can be specified in user space, outside the kernel. This ensures that the naming policy is removed from the kernel and allows a greater degree of flexibility in naming each device.

For more information on using udev and how to set it up, please see the documentation that comes bundled with the udev package in your distribution.

All a device driver needs to do in order for udev to work properly with it is to ensure that any major and minor numbers assigned to a device controlled by the driver are exported to user space via sysfs. For any driver that uses the subsystem to give it a major and minor number, this is already done by the subsystem and the driver doesn't have to do any work. Examples of subsystems that do this are the tty, misc, usb, input, scsi, block, i2c, network, and frame buffer subsystems. If your driver handles getting the major and minor number itself via cdev_init or the deprecated register_chrdev , the driver must be modified to make udev work properly with it.

udev looks in the /class/ tree in sysfs for a file named dev to determine which major and minor number is assigned to a given device when it is called by the kernel via the /sbin/hotplug interface. The device driver simply needs to create such a file for each device it controls. Typically, the class_simple interface is the easiest way to do this.

As mentioned in the "class_simple interface" section, the first step in using the class_simple interface is to create a class_simple struct by calling the class_simple_create function:

static struct class_simple *foo_class;

foo_class = class_simple_create(THIS_MODULE, "foo");

if (IS_ERR(foo_class)) (

Printk(KERN_ERR "Error creating foo class.\n");

Goto error;

This code creates a directory in sysfs at /sys/class/foo .

Whenever the driver finds a new device and you assign it a minor number, as described in Chapter 3, the driver must call the class_simple_device_add function:

class_simple_device_add(foo_class, MKDEV(FOO_MAJOR, minor), NULL, "foo%d", minor);

This code causes a subdirectory named fooN to be created in /sys/class/foo , where N is the minor number for this device. A single file is created in this directory, dev , which is exactly what udev needs to create a device node for your device. When your driver is released from a device and you discard the minor number that was assigned to it, a call to class_simple_device_remove is required to remove the sysfs entry for that device:

class_simple_device_remove(MKDEV(FOO_MAJOR, minor));

Later, when your entire driver goes down, it is necessary to call class_simple_destroy to remove the class you originally created by calling class_simple_create :

class_simple_destroy(foo_class);

The file dev , which is created by calling class_simple_device_add , consists of a major and minor number separated by a : character. If your driver doesn't want to use the class_simple interface because you want to provide other files inside the class directory for the subsystem, use the print_dev_t function to correctly format the major and minor numbers for each device.

mob_info