Air comes into the cylinder and is expelled back out after combustion through holes at the top. But since you need a closed system in order to compress the fuel/air mixture and create power, there are two valves covering those holes—the intake and the exhaust valve. How and when these valves open and close is a key factor in engine operation.
Valves open and close thanks to the camshaft, a rotating cylinder of metal that runs the length of the engine. The camshaft is a piece of hardened steel with multiple lobes attached along its length. These lobes are effectively just little humps. As the camshaft turns, the humps raise a little hydraulic piston called a lifter (some engines use solid lifters). These lifters are attached to a metal pushrod. The tubes you can see running along the cylinder on the outside contain these pushrods. At the top of the pushrod under the cylinder cover is a rocker arm, which is sort of like a seesaw. On the other end of the rocker arm is the end of the valve, called the stem. So, when the camshaft turns, the lobe pushes up the lifter, which moves the pushrod, tilting the rocker arm, and pushing down on the valve stem. When the lifter slides down off the lobe, the pressure comes off that particular pushrod and springs close the valve tight.
Camshafts tend to be very reliable as long as an airplane is flown often. That’s because they are only oiled via splashing inside the engine case, and not directly through pressurized holes. It’s not hard to imagine moist air inside the engine quickly corroding the camshaft as it sits unprotected for weeks.
Valves can stick open or closed, which can bend the pushrod as pressure is applied on both sides. If this happens the engine will run very rough, but rarely quit completely. There’s hope that flying with unleaded fuel in the future will reduce valve sticking. Airplane owners who fly regularly and check the oil filter and oil analysis go a long way toward preventing corrosion and identifying it early if some starts to creep up.